Marius Vasile

Marius Vasile

  • 589
  • 1.9k
  • 148.5k

Bootstrap collapse not working on a list view

Nov 17 2024 8:42 AM

I have a list view binded to an sqlquery to a ListView. What I want is on click to load data and display for Unitatea 1 but click on Unitatea 2 to hide data for Unitatea 1 and display data only for Unitatea 2.

HTML

<div id="DivP" runat="server">
    <div class="row no-gutters">
        <asp:ListView ID="LV1" runat="server">
            <ItemTemplate>
                <asp:TextBox ID="txtIDOB" class="hidden" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"IdOB")%>' />
                <asp:Button ID="BTNObiectiv" runat="server"
                    Text='<%#Eval("Obiectiv")%>'
                    OnClick="LV1_Click"
                    UseSubmitBehavior="false"
                    Style="font-size: 11px; background-color: lightgreen" class="btn form-control form-control-sm"
                    data-toggle="collapse" data-target="#DivS" aria-expanded="false" aria-controls="DivS"
                    ClientIDMode="Static" />

                <div id="DivS" runat="server" class="collapse">
                    <hr style="border: 1px solid #800080" />
                    <asp:ListView ID="LV2" runat="server">
                        <ItemTemplate>
                            <asp:TextBox ID="txtIDCL" class="hidden" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"IdCL")%>' />
                            <asp:Button ID="BTNCladire" runat="server"
                                Text='<%#Eval("Cladire")%>'
                                OnClick="LV2_Click"
                                UseSubmitBehavior="false"
                                Style="font-size: 11px; background-color: lightsalmon" class="btn form-control form-control-sm"
                                data-toggle="collapse" data-target="#DivS" aria-expanded="false" aria-controls="DivT"
                                ClientIDMode="Static" />

                            <div id="DivT" runat="server" class="collapse">
                                <hr style="border: 1px solid #800080" />
                                <asp:ListView ID="LV3" runat="server">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtIDCA" class="hidden" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"IdCA")%>' />
                                        <asp:Button ID="BTNCamera" runat="server"
                                            Text='<%#Eval("Camera")%>'
                                            OnClick="LV3_Click"
                                            UseSubmitBehavior="false"
                                            Style="font-size: 11px; background-color: lightblue" class="form-control form-control-sm"
                                            data-toggle="collapse" data-target="#DivS" aria-expanded="false" aria-controls="DivT"
                                            ClientIDMode="Static" />
                                    </ItemTemplate>
                                </asp:ListView>
                                <hr style="border: 1px solid #800080" />
                            </div>
                        </ItemTemplate>
                    </asp:ListView>
                    <hr style="border: 1px solid #800080" />
                </div>
            </ItemTemplate>
        </asp:ListView>
    </div>
</div>

code behind

protected void LV1_Click(object sender, EventArgs e)
{
    Button cmd = (Button)sender;
    ListViewItem ObiectivRow = (ListViewItem)cmd.NamingContainer;

    TextBox id = (TextBox)ObiectivRow.FindControl("txtIDOB");
    ListView LV2 = (ListView)ObiectivRow.FindControl("LV2");

    int idob = Convert.ToInt32(id.Text);

    List<SqlParameter> prm = new List<SqlParameter>
    {
        new SqlParameter("@IdOB", idob)
    };

    LV2.DataSource = GetDataTable("SELECT DISTINCT IdCL,Cladire FROM tblCladire WHERE IdOB= @IdOB;", prm);
    LV2.DataBind();

}

protected void LV2_Click(object sender, EventArgs e)
{
    Button cmd = (Button)sender;
    ListViewItem CladireRow = (ListViewItem)cmd.NamingContainer;

    TextBox id = (TextBox)CladireRow.FindControl("txtIDCL");
    int idcl = Convert.ToInt32(id.Text);
    ListView LstCamera = (ListView)CladireRow.FindControl("LV3");


    List<SqlParameter> prm = new List<SqlParameter>
    {
        new SqlParameter("@IdCL", idcl)
    };

    LstCamera.DataSource = GetDataTable("SELECT DISTINCT IdCA,Camera FROM tblCamera WHERE IdCL =@IdCL;", prm);
    LstCamera.DataBind();

}

an image of the displayed data


Answers (3)