I have a cascaded ListView and I want to reach objects in lvl1 from lvl2
VB.NET
' />
'
OnClick="LV1_Click"
UseSubmitBehavior="false"
Style="font-size: 11px; background-color: lightgreen; width: 200px;" class="btn form-control form-control-sm"
ClientIDMode="Static" />
' />
'
OnClick="LV2_Click"
UseSubmitBehavior="false"
Style="font-size: 11px; background-color: lightsalmon; width: 180px;" class="btn form-control form-control-sm"
ClientIDMode="Static" />In code behind I handle the conection with:
C#
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


Sophia CarterRank #4,018 · 371 reputationPosted May 2, 2025, 1:52 AM EDT
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:
protected void LV2_Click(object sender, EventArgs e) { Button cmd = (Button)sender; ListViewItem CladireRow = (ListViewItem)cmd.NamingContainer; // Find the reference to LV1 ListView LV1 = (ListView)CladireRow.NamingContainer.NamingContainer; // Access the LstCladire control within LV1 ListView LstCladire = (ListView)LV1.FindControl("LV2"); // Disable LstCladire LstCladire.Visible = false; // Continue with the rest of your logic... }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.
Marius VasileRank #785 · 2.9K reputationPosted May 2, 2025, 2:08 AM EDT
Well, The AI solution works up to a point. I used enable instead of visible but it will disable the list within in lvl2
// Find the reference to LV1 ListViewItem LV1 = (ListViewItem)CladireRow.NamingContainer.NamingContainer; // Access the LstCladire control within LV1 ListView LstCladire = (ListView)LV1.FindControl("LV2"); 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; // Disable LstCladire LstCladire.Enabled = false; ListView LstCladire = (ListView)LV1.FindControl("LV2");so LstCota is now disabled even if I add
LstCota.Enabled = true;