Index of GridView Row clicked

Discussion in 'ASP .Net' started by Abhishek Tripathi, Nov 3, 2006.

  1. I have a gridview which has a custom buttonfield. I have written
    appropriate code in the GridView1_RowCommand function. How can I find
    the number of row from which the event is being generated? For example,
    how can I know if the user clicked on the 2nd row of the gridview ?
    Gridview1.selectedIndex returns -1 . Kindly assist
     
    Abhishek Tripathi, Nov 3, 2006
    #1
    1. Advertising

  2. Abhishek Tripathi

    Guest

    Hello,

    Here is the code. I have taken a GridView with two columns. First is
    ButtonField type to which assigned CommandName as "Select" and second
    column is BoundText type.

    private void CustomersGridView_RowCommand(Object sender,
    GridViewCommandEventArgs e)
    {
    if (e.CommandName == "Select")
    {
    int index = Convert.ToInt32(e.CommandArgument);
    GridViewRow selectedRow =
    CustomersGridView.Rows[index];
    string strValue = selectedRow.Cells[1].Text;
    Response.Write(strValue);
    }
    }

    Abhishek Tripathi wrote:
    > I have a gridview which has a custom buttonfield. I have written
    > appropriate code in the GridView1_RowCommand function. How can I find
    > the number of row from which the event is being generated? For example,
    > how can I know if the user clicked on the 2nd row of the gridview ?
    > Gridview1.selectedIndex returns -1 . Kindly assist
     
    , Nov 3, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H5N1
    Replies:
    0
    Views:
    2,771
  2. Replies:
    5
    Views:
    697
  3. =?Utf-8?B?cGI2NDgxNzQ=?=

    Getting the value for a clicked row in a Repeater or GridView

    =?Utf-8?B?cGI2NDgxNzQ=?=, Dec 27, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,038
    =?Utf-8?B?cGI2NDgxNzQ=?=
    Dec 27, 2006
  4. Chris

    Highlight a clicked row in a gridview linked to a css

    Chris, Feb 8, 2007, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    238
    Steven Cheng[MSFT]
    Feb 13, 2007
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    361
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page