I need to fill tree view with parent child on razor asp.net core but I don't know how to fill tree view parent child
and child can select checkbox and can see related chid for every parent
my code with web form csharp
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillModuleName(); } } private void FillModuleName() { string sql = ""; clsDB obj = new clsDB(Session["g_ConnectionString"].ToString()); DataSet ds = new DataSet(); DataSet ds1 = new DataSet(); int i = 0; try { sql = "select * from tblWebModule where parentmenucode='00'"; ds = obj.ExecuteQuery(sql); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { TreeNode TN = new TreeNode(); TN.Text = dr["MenuName"].ToString(); TN.Value = dr["ChildMenuCode"].ToString(); sql = "select * from tblWebModule where parentmenucode='" + dr["ChildMenuCode"].ToString() + "'"; ds1 = obj.ExecuteQuery(sql); foreach (DataRow rw in ds1.Tables[0].Rows) { TreeNode CN = new TreeNode(); CN.Text = rw["MenuName"].ToString(); CN.Value = rw["ChildMenuCode"].ToString(); TN.ChildNodes.Add(CN); } tvModules.Nodes.Add(TN); } } } catch (Exception ex) { } } on html tree view as below <tr> <td align="left" style="width: 100px; height: 24px"> </td> <td align="left" style="width: 500px; height: 24px"> <asp:TreeView ID="tvModules" runat="server" ShowCheckBoxes="All" Font-Names="Verdana" Font-Size="Small" ImageSet="BulletedList"> </asp:TreeView> </td> <td align="left" style="width: 100px; height: 24px"> </td> </tr> <tr>
so please How to organize this code on razor page model as below
page model
public void OnGet()
{
How to load tree view parent and child
}
on treeview.cs.html
layout
How to link page model with html to load tree view
<asp:TreeView ID="tvModules" runat="server" ShowCheckBoxes="All" Font-Names="Verdana" Font-Size="Small" ImageSet="BulletedList"> </asp:TreeView>
sample for result expected