所以我有一个 ListView ,里面有一个复选框和两个单选按钮。该复选框控制禁用或启用单选按钮的位置。
正如您所看到的,我让它适用于列表中的第一项 (items[0]),但是如何让它适用于 ListView 中的其余行?
谢谢
System.Web.UI.WebControls.ListView lv2 = ListView1.Items[0].FindControl("ListView2") as System.Web.UI.WebControls.ListView;
CheckBox cb = lv2.Items[0].FindControl("ChargedCB") as CheckBox;
RadioButton acceptRB = lv2.Items[0].FindControl("AcceptedRB") as RadioButton;
RadioButton disputedRB = lv2.Items[0].FindControl("DisputedRB") as RadioButton;
if (cb.Checked == false)
{
acceptRB.Checked = false;
disputedRB.Checked = false;
acceptRB.Enabled = false;
disputedRB.Enabled = false;
}
else
{
acceptRB.Enabled = true;
disputedRB.Enabled = true;
}
最佳答案
for(int k = 0;k<ListView1.Items.Count;k++)
{
System.Web.UI.WebControls.ListView lv2 = ListView1.Items[k].FindControl("ListView2") as System.Web.UI.WebControls.ListView;
for(int i = 0; i<lv2.Items.Count;i++)
{
CheckBox cb = lv2.Items[i].FindControl("ChargedCB") as CheckBox;
RadioButton acceptRB = lv2.Items[i].FindControl("AcceptedRB") as RadioButton;
RadioButton disputedRB = lv2.Items[i].FindControl("DisputedRB") as RadioButton;
if (cb.Checked == false)
{
acceptRB.Checked = false;
disputedRB.Checked = false;
acceptRB.Enabled = false;
disputedRB.Enabled = false;
}
else
{
acceptRB.Enabled = true;
disputedRB.Enabled = true;
}
}
}
关于ListView 中的 ASP.NET 复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17592286/