how to get selected LinkButton in ListView

Total Post:117

Points:821
 1244  View(s)
Ratings:
Rate this:

I have a listview which contains a column where I need to put two link buttons - Open and Download to open and download a server file respectively. I have an id column for each row of the list view. I have set the DataKeyNames property of listview to "ID" and verified that DataKeys get populated with the row values. On clicking a particular link button I need the selected ID to determine the link of the server file corresponding to that row. I have added the linkButton_click event but when I try to access SelectedDataKey inside the handler it remains null. How can I get the ID inside the click handler of the link button

  1. Post:378

    Points:2694
    Re: how to get selected LinkButton in ListView

    you can use this:

     protected void ConferencesListView_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            int _Id;
            int.TryParse(e.CommandArgument.ToString(), out _Id);
            if(e.CommandName == "View")
            {
            }
        }

    and in designer:

     <asp:LinkButton  ID="ViewLinkButton" runat="server" CommandName="View" CommandArgument='<%# Eval("ID") %>' />

      Modified On Apr-06-2018 11:31:39 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!