2

所以我有一个列表视图,里面有一个复选框和两个单选按钮。复选框控制单选按钮的禁用或启用位置。

正如你所看到的,我让它适用于列表中的第一项(items [0]),但我如何让它适用于列表视图中的其余行?

谢谢

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;
            }
4

1 回答 1

2
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;
                    }
    }
}
于 2013-07-11T11:54:30.387 回答