"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, November 8, 2011

Passing Primary Key to RowCommand Event

Hi *.*,
I know its a old topic,For a beginner its a grt help!!!!

Code:

<asp:GridView ID="GridViewNotSelected" runat="server" AllowSorting="True"
       
AutoGenerateColumns="False"
       
DataSourceID="SqlDataSourceTagsNotSelected"
       
onrowcommand="GridViewNotSelected_RowCommand">
   
<Columns>
       
<asp:TemplateField ShowHeader="False">
           
<ItemTemplate>
               
<asp:LinkButton ID="LinkButton1" runat="server"
                   
CausesValidation="False" CommandArgument='<%# Eval("Id") %>'
                   
CommandName="Select" Text="Select"></asp:LinkButton>
           
</ItemTemplate>
       
</asp:TemplateField>
   
</Columns>
</asp:GridView>
 C#
protected void GridViewNotSelected_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int tagsId = Convert.ToInt32(e.CommandArgument);
}
 VB.net
        Protected Sub GridViewNotSelected_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
            Dim tagsId As Integer = Convert.ToInt32(e.CommandArgument)
        End Sub




If u had any trouble just ask, Happy to help u :)
Stay Tune... Have a nice day... 'N happy Coding :)

No comments: