Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 15, 2012 09:00 PM by davrob01
Sep 07, 2006 03:13 PM|LINK
I have a GridView control and I added
a ‘ButtonField’ to it. I am trying to wire the ‘onClick’ event of the button to a procedure and pass the ID of the line item from which the button was clicked.
Is there a simple to do this?
The GridView code:
/> 'this is where I want to pass the 'ID' to procedure
I’ts got to be me – I don’t know what I’m missing, but I can’t seem to find a way to do it.
Sep 07, 2006 05:54 PM|LINK
Convert your Button field to a Template field with a Button in it and use the GridView RowCreated or RowDataBound event to set the CommandArgument of the button to the RowIndex.
Sep 08, 2006 12:47 AM|LINK
I am looking for a way to pass the ID as a command arg - unless there is a way to use the index of the row clicked to get the ID.
I've been searching this all over and could not find an answer - is it a hidden art?
Is there a way to assign the ID to the command argument in a button field?
Sep 08, 2006 01:24 AM|LINK
May this helps:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
if (e.Row.RowType ==DataControlRowType.DataRow)
//Button myButton = (Button)e.Row.Cells.Controls;
//myButton.CommandArgument = e.Row.RowIndex.ToString();
Sep 08, 2006 01:38 AM|LINK
For the Id use - gv_1.DataKeys(rowindex).Value
You can assign the id to the CommandArgument when grid is created or assign the rowindex and retrieve the DataKey on the click event of the button. Makes no difference but I prefer latter for a more consistent approach.
Sep 11, 2006 04:28 PM|LINK
Thank you - I get it now...
Protected Sub gv_rowCommand(s
As Object, e
As integer =
As String =
May 01, 2008 09:21 PM|LINK
Don't Forget that you have to wire up the aspx page's formview control using the OnRowCommand construction:
Nov 27, 2008 01:51 AM|LINK
FYI, remember to set the
DataKeyNames property when you define your GridView if you want to use the DataKeys example above.
Apr 20, 2009 10:42 PM|LINK
I like the idea of just accessing the key value of the row being clicked but could you expound more about doing so? I have a grid with a buttonfield. I can set the command name but not the argument. Then I assume the function that would be called when the
user clicks on the button is OnRowCommand? Then once in the code behind how do you know which button was selected if you don't have the argument already set?
If anyone could provide a simple example of gridview using a buttonfield that when clicked in the code behind i can get to the value of my row I'd appriecieate it!
Feb 11, 2010 07:51 AM|LINK
I would prefer
CommandArgument='<%# eval("MyRowId") %>'
Sub btnRemove_Command(ByVal sender
Integer = e.CommandArgument
databinding gridView buttonfield linkbutton