ListView 中的 ASP.NET 复选框

标签 asp.net listview checkbox

所以我有一个 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/

相关文章:

asp.net - Nginx 无法将 Docker 部署到 Amazon

android - ListView 中每一行的背景

jquery - append 一个 div,具体取决于选中的单选按钮

javascript - VueJS 只允许根据类名选择 1 个复选框

c# - 尝试在 ASP.NET 应用程序中读取/写入文件时出现权限问题

c# - Response.Redirect 与不同的推荐人

c# - Entity Framework 在加载 DynamicProxies 时挂起

android - 为什么在自定义 ArrayAdapter 中实例化新的自定义处理程序有效?

android - 如何在我的 fragment 和适配器中添加更多负载

javascript - 有什么方法可以使用纯 CSS 在单击时隐藏复选框父 div?