Click here to Skip to main content
16,020,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir

I have taken a template button in Grid View of a web form and i want to retrieve the row index when a user click on the template button. How can i do that ? Please help me sir ..


thakns in advance...
Posted

on row command of gridview
C#
protected void cmd_transfer(object sender, GridViewCommandEventArgs e)
   {
       int index = Convert.ToInt32(e.CommandArgument);
       GridViewRow row = GridView1.Rows[index];
       ViewState["fileno"] = row.Cells[2].Text;

       this.modal1.Show();
   }
 
Share this answer
 
Hi,

You can retrieve that in any way one of the way is here

C#
//On row command event
  int rindex=e.rowIndex


All the Best
 
Share this answer
 
hi,

here is one of the way to get the row index of the grid

the sample code:

protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = grd.PageIndex * grd.PageSize + Convert.ToInt32(e.CommandArgument);
}


Here command argument is like

CommandArgument='<%#Container.DisplayIndex%>'


Hope it will work
 
Share this answer
 
do by this way..

1)aspx page

XML
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BtnDelAll" runat="server" CssClass="bluearrow4" ToolTip="Click to Delete"  Enabled="true" CommandName="delete" Text="mybtn"/> </ItemTemplate></asp:TemplateField>




2)code behind Page

C#
protected void gvinspec_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {
      int row = e.RowIndex;

  }
 
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