|
|
<asp:ListView ID="lvProducts" runat="server" DataSourceID="SqlDataSource1"
OnItemCommand="lvProducts_ItemCommand" ItemPlaceholderID="PlaceHolder1">
<LayoutTemplate>
<asp:Placeholder
id="PlaceHolder1"
runat="server" />
</LayoutTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("ProductID") %>'
Text='<%# Eval("ProductName") %>' CommandName="View Details"
runat="server"></asp:LinkButton><br />
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products]">
</asp:SqlDataSource>
C#
protected void lvProducts_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "View Details")
{
int productId = (int)e.CommandArgument;
}
}
VB.NET
Protected Sub lvProducts_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
If e.CommandName = "View Details" Then
Dim productId As Integer = CInt(e.CommandArgument)
End If
End Sub
'Like' us on our FaceBook page if you find this blog useful. Thanks!
Did you like this post?
|
|
|
||
|
|
|
|
Save on Delicious |
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |





comments
1 Response to "Handling events of Control's inside ASP.NET ListView"Many thanks - this is really clear and allows me to get out of a hole I had dug for myself!
Post a Comment