Click here to Skip to main content
12,394,769 members (64,431 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 21-Oct-11 1:31am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

on row command of gridview
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();
   }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

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

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

All the Best
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

do by this way..

1)aspx page

<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

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100