how to get selected LinkButton in ListView

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

Last updated:11/20/2014 11:45:15 PM

1 Answers

Sumit Kesarwani
Sumit Kesarwani

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') %>' />

Answer