2

So I have a list view and inside I have a checkbox and two radio button. The checkbox controlls where the radiobuttons are disabled or enabled.

As you can see I have it working for the first item in the list (items[0]) but how do I make it work for the rest of the rows in the list view?

Thanks

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;
            }
1
  • But here it appears you have listview1 and inside it there is lv2 on the first row and inside lv2 there is checkbox and 2 radio buttons per row ? So you want to do this foreach nested listview lv2 in listview1 ? Commented Jul 11, 2013 at 11:52

1 Answer 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;
                    }
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Does not work. lv2 cannot be found in the second loop and .Length is also not recognised.
1st, replace Length with Count !. You need to try a little bit :). 2nd: Please explain more your structure of your listviews ListView1 and ListView2, because i mentioned 2 ways, and each is for a different structure. do you have only one ListView2 or on each row of ListView1 you have a "ListView2" ?
I have a list view inside a list view. So for every row in listview1 there is a listview 2 row. Inside listview 2 there is the checkbox and radio buttons.
You need the 2nd method i described, i will remove the first 1. Please apply and update me if you get any exceptions with details :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.