I have a cascaded ListView and I want to reach objects in lvl1 from lvl2
In code behind I handle the conection with:
protected void LV1_Click(object sender, EventArgs e)
{
Button cmd = (Button)sender;
ListViewItem ObiectivRow = (ListViewItem)cmd.NamingContainer;
TextBox id = (TextBox)ObiectivRow.FindControl("txtOID");
ListView LstCladire = (ListView)ObiectivRow.FindControl("LV2");
LstCladire.DataSource = null;
LstCladire.DataBind();
int oid = Convert.ToInt32(id.Text);
List prm = new List
{
new SqlParameter("@OID", oid)
};
LstCladire.DataSource = GetDataTableEvaris("SELECT DISTINCT CID,Cladire FROM tblCladire WHERE OID= @OID;", prm);
LstCladire.DataBind();
if (LstCladire.Visible)
{
LstCladire.Visible = false;
return;
}
LstCladire.Visible = true;
SqlParameter prmS = new SqlParameter("@OID", oid);
hiddenObiectiv.Text = ExecuteScalar("SELECT DISTINCT Obiectiv FROM tblObiectiv WHERE OID= @OID;", prmS);
hiddenObiectiv.Visible = true;
hiddenCladire.Text = string.Empty;
hiddenCota.Text = string.Empty;
hiddenCamera.Text = string.Empty;
}
protected void LV2_Click(object sender, EventArgs e)
{
Button cmd = (Button)sender;
ListViewItem CladireRow = (ListViewItem)cmd.NamingContainer;
TextBox id = (TextBox)CladireRow.FindControl("txtCID");
ListView LstCota = (ListView)CladireRow.FindControl("LV3");
LstCota.DataSource = null;
LstCota.DataBind();
int cid = Convert.ToInt32(id.Text);
List prm = new List
{
new SqlParameter("@CID", cid)
};
//aici se incarca imaginea pentru cota
LstCota.DataSource = GetDataTableEvaris("SELECT DISTINCT EID,Cota FROM tblCota WHERE CID = @cid;", prm);
LstCota.DataBind();
if (LstCota.Visible)
{
LstCota.Visible = false;
return;
}
LstCota.Visible = true;
SqlParameter prmS = new SqlParameter("@CID", cid);
hiddenCladire.Text = ExecuteScalar("SELECT DISTINCT Cladire FROM tblCladire WHERE CID= @CID;", prmS);
hiddenCladire.Visible = true;
hiddenCota.Text = string.Empty;
hiddenCamera.Text = string.Empty;
}
But I want to disable LstCladire which is in LVL1 from LVL2 procedure on a button click
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Marius VasilePosted May 2, 2025, 6:08 AM
Well, The AI solution works up to a point. I used enable instead of visible but it will disable the list within in lvl2
so LstCota is now disabled even if I add
LstCota.Enabled = true;
Sophia CarterPosted May 2, 2025, 5:52 AM
To disable the ListView `LstCladire` which is in `LV1` from the code handling the button click in `LV2`, you would need to establish a reference back to `LV1` and then access the `LstCladire` ListView to disable it.
Here's a suggested approach:
1. On the click event of `BTNCladire` button in `LV2`, you can traverse up the control hierarchy to find the parent `LV1` control.
2. Once you have a reference to `LV1`, you can then locate the `LstCladire` control within it and disable it.
Below is a modified version of your `LV2_Click` method:
By using this method, you should be able to disable the `LstCladire` ListView in the `LV1` from the click event handling logic in `LV2`. This approach ensures that you can navigate through the control hierarchy and access controls from different levels within your `ListView` structure.