- 爱易网页
-
ASP.NET教程
- 遍历checkbox及部分选取有关问题
日期:2014-05-18 浏览次数:20451 次
遍历checkbox及部分选取问题
下面是我写的一段程序的部分代码,目的是实现树型目录,同时给每一项中添加一个checkbox.现在树型目录的显示和赋值都没问题。
但checkbox取不到值,还有我想实现选取上一级目录的checkbox时,属于它这一层的
checkbox同时选中,不知如何实现。请大家帮忙!
private string ShowTree()
{
string ConnSql1= " ";
string ConnSql2= " ";
string ConnSql3= " ";
string ConnSql4= " ";
string ConnSql5= " ";
ConnSql1= "select ID,Name from WebStruct where ParentID= '0 ' order by OrderN ";
DataSet RsCatalog1=new DataSet ();
RsCatalog1=Dbc.getBinding (ConnSql1, "s "); strTree= " <div style= 'cursor:hand '> ";
if (RsCatalog1.Tables[0].Rows.Count> 0)
{
for (int i=0;i <RsCatalog1.Tables[0].Rows.Count;i++)
{
ConnSql2= "select ID,Name from WebStruct where ParentID= ' "+RsCatalog1.Tables[0].Rows [i][ "ID "].ToString() + " ' order by OrderN ";
DataSet RsCatalog2=new DataSet ();
RsCatalog2=Dbc.getBinding (ConnSql2, "s ");
if (RsCatalog2.Tables[0].Rows.Count> 0)
{
strTree=strTree+ " <IMG SRC= '../images/folder.gif ' border=0 ID= 'Gradesi "+i+ " ' CLASS= 'Outline ' WIDTH= '16 ' HEIGHT= '16 '> <INPUT type= 'CheckBox ' ID= ' "+RsCatalog1.Tables[0].Rows [i][ "ID "].ToString()+ " ' Text= ' "+RsCatalog1.Tables[0].Rows [i][ "Name "].ToString()+ " '> "+RsCatalog1.Tables[0].Rows [i][ "Name "].ToString()+ " <br> ";
strTree=strTree+ " <DIV ID=Gradesi "+i+ "d STYLE= 'display:none ' CLASS= 'hide '> ";
for (int j=0;j <RsCatalog2.Tables[0].Rows.Count;j++)
{
ConnSql3= "select ID,Name from WebStruct where ParentID= ' "+RsCatalog2.Tables[0].Rows [j][ "ID "].ToString() + " ' order by OrderN ";
DataSet RsCatalog3=new DataSet ();
RsCatalog3=Dbc.getBinding (ConnSql3, "s ");
}
strTree=strTree+ " </div> ";
}
else
{ strTree=strTree+ " <IMG SRC= '../images/ofolder.gif ' border=0 WIDTH= '16 ' HEIGHT= '16 '> <INPUT type= 'CheckBox ' ID= ' "+RsCatalog1.Tables[0].Rows [i][ "ID "].ToString()+ " ' Text= ' "+RsCatalog1.Tables[0].Rows [i][ "Name "].ToString()+ " '> "+RsCatalog1.Tables[0].Rows [i][ "Name "].ToString()+ " <br> ";
}
}
}
else
{
strTree=strTree+ " <font color=red> <b> 尚未添加数据,请与系统管理员联系! </b> </font> ";
}
strTree=strTree+ " </div> ";
return strTree;
}
------解决方案--------------------