数据库中内容如下:
菜单     父菜单
a          0
a1         a
a2         a
b          0
b1         b
b2         b
...
首先写一个用户控件,内容是一张表格,两列:label和checkbox
然后在主页上多次调用这个控件,每个用户控件加载一个父菜单对应的内容
主页代码如下:
SqlConnection cn= new SqlConnection (strConnection);
cn.Open ();
string mysql= "select MenuName from T_Menu where parentid='0'";
SqlCommand cm=new SqlCommand  (mysql,cn);
SqlDataReader dr=cm.ExecuteReader ();
System.Collections.ArrayList bs=new System.Collections.ArrayList();
while(dr.Read())
{
for(int i=0;i<dr.FieldCount;i++)
{
           string ab= dr.GetValue(i).ToString();
  bs.Add(ab);
  Session["ab"]=ab;
  test3 a=(test3)LoadControl("test3.ascx");
           ((LinkButton)(a.FindControl("LinkButton1"))).Text=ab;
           string strSQL="select MenuName from T_Menu where parentid='"+((LinkButton)(a.FindControl("LinkButton1"))).Text+"'";
DataSet ds=new DataSet ();
SqlConnection objConnection=new SqlConnection (strConnection);
SqlDataAdapter da=new SqlDataAdapter (strSQL,objConnection);
da.Fill (ds,"Data1");
Session["MyData"]=ds;
((DataGrid)(a.FindControl("DataGrid1"))).DataSource =ds.Tables         ["Data1"];
((DataGrid)(a.FindControl("DataGrid1"))).DataBind ();
objConnection.Close ();
}
               
}

cn.Close(); Session["bs"]=bs;已完成内容运行后界面如下:a
a1  口
a2  口b   口
b1  口
b2  口
            button现在的问题是,怎样实现:用户控件的表格每行对应一个checkbox,选中checkbox表示该行表示的菜单为激活状态。在主页上有一个button,选择某些checkbox后,点击button可以把checkbox选中的
行对应的数据表中的check1字段设置为true/false由于用户控件是动态加载的,因此不知道把实现上述功能的代码写在主页还是用户控件的cs代码里
也不知道怎样取得所有动态加载的控件请大家帮忙,多谢!