Winston Madiano
Winston Madiano

Reputation: 87

Get selected ID in asp.net listview bound to a hyperlink

I am new to asp.net, forgive my newbie question. I have a listview which displays all item info (ItemID,Item name). I bound the item name to a hyperlink control. now what i want to do is that when i click the hyperlink i want to get the ID and navigate the item detail page. i tried using selected index but it still returns null. here's my code.

On the listview itemTemplate code

<asp:HyperLink ID="HyperLink1" runat="server" 
NavigateUrl="ItemDetails.aspx"> <%# Eval("[ItemName]") %> 
</asp:HyperLink>

<asp:Label ID="Label1" runat="server"  Text='<%# Eval("[ItemID]") %>'/>

Please help.thanks in advance

Upvotes: 0

Views: 3046

Answers (1)

Nag
Nag

Reputation: 689

Instead of Hyperlink, I used LinkButton in ItemTemplate If u want to pass the selectedId to the next page u can pass using Query String

<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="120px">
 <ItemTemplate>
 <asp:LinkButton ID="lnk_ViewDetails" runat="server" Text='View Details' PostBackUrl='<%#"~/ViewDetailss.aspx?Id="+Eval("ID")%>'></asp:LinkButton>
 </ItemTemplate>
  </asp:TemplateField>

If u want to encrypt querystring Please refer This Link

Upvotes: 2

Related Questions