我有段代码出了问题,大家帮忙解决一下。
c#吧
全部回复
仅看楼主
level 4
haostyle 楼主
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = ((GridViewRow)(((DropDownList)sender).NamingContainer)).RowIndex;
DropDownList ddl = GridView1.Rows[index].Cells[2].FindControl("DropDownList1") as DropDownList;
int n = ddl.Items.Count;
for (int i = 0; i < n; i++)
{ if(ddl.Items[i].Selected){ CheckBoxList1.Items[index].Value = ((DropDownList)sender).SelectedValue;
CheckBoxList1.Items.Add(ddl.Items[i].Value);
}
}
}
2012年07月25日 06点07分 1
level 4
haostyle 楼主
2012年07月25日 06点07分 2
level 4
haostyle 楼主
我刚学习C#,就是创建一个gridview,里面有个dropdownlist。 通过选择dropdownlist的值,加入到checkboxlist中。 但是我要第一行的dropdownlist值,放入checkboxlist第一项中。。
不知道这样写对不对。
2012年07月25日 06点07分 3
level 10
虽然不知道你要干什么,但是放入第一项的话改成下面试试
CheckBoxList1.Items[0].Value = ((DropDownList)sender).SelectedValue;
2012年07月26日 03点07分 4
level 1
inedx的值超过你定义的
ddl.Items.Count的值
2012年07月26日 18点07分 6
嗯,我知道错误了。
2012年07月27日 00点07分
1