Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my aspx code
<pre lang="xml"><asp:TemplateField HeaderText="Submit" ItemStyle-HorizontalAlign="Center">
       <ItemTemplate>
       <asp:LinkButton ID="lnkSubmit" runat="server" CommandName="Submit" Text="Action" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' ></asp:LinkButton>
       </ItemTemplate>
       <EditItemTemplate>
       </EditItemTemplate>

Here is my aspx.cs code
C#
protected void GridView1_RowCommand(object Sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName.Equals("Submit"))
       {
           GridViewRow FItem = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
           int RowIndex = FItem.RowIndex;
           lblRowIndex.Text = "Row Index =" + RowIndex.ToString();
           Response.Redirect("InquiryReg.aspx");
       }

   }

I am getting the Row Index but i cant get the row id.
Posted

1 solution

The simplest solution would be to store the ID in the command argument:
aspx
<asp:LinkButton ID="lnkSubmit" runat="server" CommandName="Submit" Text="Action" CommandArgument='<%# Eval("ID") %>' />

C#
protected void GridView1_RowCommand(object Sender, GridViewCommandEventArgs e)
{
   if (e.CommandName.Equals("Submit"))
   {
       string id = (string)e.CommandArgument;
       Response.Redirect("InquiryReg.aspx?id=" + Server.UrlEncode(id));
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900