Asked by:
dynamic treeview control with multiple checkboxes per node/item

Question
-
User-153404742 posted
I can have a treeview that's populated from database and have a checkbox for each item....however, I want to design it so that each node/item has 3 or possibly 4 checkboxes horizontally.....Is there a good design for this...how do I attach a checkboxlist or individual mutliple checkboxes per item?
Monday, August 19, 2019 8:19 PM
All replies
-
User288213138 posted
Hi inkaln,
There is property called ShowCheckBoxes in treecontrol, it is used to gets or sets a value indicating which node types will display a check box in the TreeView control.
You can set ShowCheckBoxes="All".
The code:
<asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All"> </asp:TreeView> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = this.GetData("SELECT Id, Name FROM Test38"); PopulateTreeView(dt, 0, null); } } private void PopulateTreeView(DataTable dtParent, int parentId, TreeNode treeNode) { foreach (DataRow row in dtParent.Rows) { TreeNode child = new TreeNode { Text = row["Name"].ToString(), Value = row["Id"].ToString() }; if (parentId == 0) { TreeView1.Nodes.Add(child); DataTable dtChild = this.GetData("SELECT Id, Name FROM Test39 WHERE CustomerId = " + child.Value); PopulateTreeView(dtChild, int.Parse(child.Value), child); } else { treeNode.ChildNodes.Add(child); } } } private DataTable GetData(string query) { DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); } } return dt; } }
The result:
Best regards,
Sam
Tuesday, August 20, 2019 3:08 AM -
User-153404742 posted
I can do this...but what I need is per each of the treenodes and it's childnodes, I need to have a horizontal checkboxlist with 3 checkboxes in each.....
so by Sam 1, I need to have three checkboxes and same for n1, n2, n3, Sam2 and the rest of it. The levels could be as deep as 5 or more levels as it's all dynamic. I need to be able to have three columns per each of the nodes and have a title at the top for each of the checkboxes.
he result:
Tuesday, August 20, 2019 3:44 PM -
User288213138 posted
Hi inkaln,
inkaln
I can do this...but what I need is per each of the treenodes and it's childnodes, I need to have a horizontal checkboxlist with 3 checkboxes in each.....
so by Sam 1, I need to have three checkboxes and same for n1, n2, n3, Sam2 and the rest of it. The levels could be as deep as 5 or more levels as it's all dynamic. I need to be able to have three columns per each of the nodes and have a title at the top for each of the checkboxes
According to your description, I couldn’t understand your requirement clearly.
Do you mean you want to create horizontal nodes?
But as far as I know, the standard TreeView control doesn't provide the horizontal orientation.
Unless you could write a custom control or you could try using a horizontal Menu control, if it will fit your requirements.
If I misunderstand your requirement, please post more details information about your requirement(You can post a style image).
Best regards,
Sam
Wednesday, August 21, 2019 7:38 AM -
User409696431 posted
"According to your description, I couldn’t understand your requirement clearly."
I believe the requirement from inkaln is clear: 3 checkboxes beside each node, not just one. (There is nothing in the TreeView control that supports that requirement out of the box.)
Thursday, August 22, 2019 3:18 PM