Search code examples
asp.netrepeateraccordionlinkbutton

how to find the selected link button value in the repeater control


I have an issue regarding link button, On my website i have got a product for sale page, which has a ryt side bar with filter options while the left side bar shows the filteration results. On my ryt sidebar i have used accordion with the repeater control which display the searching criteria from database. For instance I have 2 searching criteria model and price , under model accordion there are three models, what I want to acheive is when a user clicks on that specific model , the page should run a query with respect to that click and show bind the results on the repeater of the left side bar, I know the query to get the results but I dunno how to get the value of that hyper link button, coz these buttons will be dynamic it can be 3,4 or 10. how will i get the clicked hyperlink value so that I can run the query depending on the model selected. Any help or tutorial will highly be appreciated.

            AutoSize="None"
            FadeTransitions="true"
            TransitionDuration="250"
            FramesPerSecond="40"
            RequireOpenedPane="false"
            SuppressHeaderPostbacks="true">
        <Panes>
            <asp:AccordionPane ID="AccordionPane1" runat="server" >
            <Header>
           &nbsp;&nbsp;&nbsp;Make
            </Header>
            <Content>

                <asp:Repeater ID="Repeater1" runat="server">
               <ItemTemplate>
         <li>

             <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("make") %>'></asp:LinkButton>
         </li>
               </ItemTemplate>
                </asp:Repeater>

            </Content>
            </asp:AccordionPane>
            <asp:AccordionPane ID="AccordionPane2" runat="server" >
            <Header>
            &nbsp;&nbsp;&nbsp;Price
            </Header>
            <Content>

            </Content>
            </asp:AccordionPane>
        </Panes>
        </asp:Accordion> 

Solution

  • Set the CommandArgument of the LinkButton.

    Then to access the CommandArgument:

    protected void lnkButton_Click(object sender, EventArgs e) {
        LinkButton _sender = (LinkButton)sender;
        string argument = _sender.CommandArgument;
    }