2014年7月13日 星期日

[RESOLVED] Display Checkboxlist as menu item


I have a menu control in my website where menu items(parent)  and sub menu items(child) are populate through database.


In below code ParentId=0 when its a menu item and ParentId > 0 when it's a sub menu item. The code is working fine.


if(!IsPostBack)
{
SqlConnection sqlConnection;

string dbConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
sqlConnection = new SqlConnection(dbConnectionString);
DataSet ds = new DataSet();
DataTable dt = new DataTable();

using (sqlConnection)
{
SqlCommand command = new SqlCommand("proc_GetCategories", sqlConnection);
command.CommandType = CommandType.StoredProcedure;
sqlConnection.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = command;
da.Fill(ds);
dt = ds.Tables[0];
DataRow[] drowpar = dt.Select("ParentId=" + 0);

foreach (DataRow dr in drowpar)
{
menuCategory.Items.Add(new MenuItem(dr["CategoryName"].ToString(),
dr["CategoryID"].ToString()));
}

foreach (DataRow dr in dt.Select("ParentID >" + 0))
{
MenuItem mnu = new MenuItem(dr["CategoryName"].ToString(),
dr["CategoryID"].ToString());
menuCategory.FindItem(dr["ParentID"].ToString()).ChildItems.Add(mnu);
}
}
}



Now in order to insert the menu items in database I want to create a checkboxlist with same parent child relationship as menu-submen control.


For example if I have 5 menu items with 3 sub menu items displayed each then in the same maneer checkboxlist should display 5 parent check box


with 3 checkbox child items each. On select the parent checkbox all child checkbox should be checked. Each checkbox select will have a id with it like it is with menu item.


Please help me in achieving this.



沒有留言:

張貼留言