SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an SPGridView with RowCommand event handler defined to handle link events from the grid view. I have a ButtonField on every row defined with CommandName and DataTextField. When my event handler is called though, the argument is always the row index as opposed to the value I passed in datatable for the column specified (which has an integer) for DataTextField. With this, I am unable to figure out the actual data row the link was clicked for, since my data may have changed between the initial render and the postback.

currently the postback link at client side has __doPostBack('<gridid>', '<command>$<rowindex>'), which obviously is missing the DataTextField I had passed.

Is there any way to make the ButtonField include more arguments than just the row index? Basically, I need to be able to add another integer to the argument list that I can retrieve in the command handler. Even some way to override the postback link is acceptable too.

Thanks, raja.

Additional Info:

the creation of gridview is happening in the C# code that doesn't have an ascx part to it.

C# code does something like this:

var gridview = new SPGridView { set properties: EnableViewState, ShowHeader, AutoGenerateColumns, AllowSorting, GridLines, Width, CellPadding });
gridview.Columns.Add(new HyperLinkField { set properties: HeaderText, DataTextField, DataNavigateUrlFields, and DataNavigateUrlFormatString });
gridview.Columns.Add(new ButtonField { set properties: HeaderText, DataTextFormatString, CommandName="delete", DataTextField="feedid" });// I expect "feedid" column value from my datatable to show up as the command argument! but it's ignored and I get the row index instead
gridview.RowCommand += RowCommandHandler;

gridview.DataSource = new DataView(table);


share|improve this question
Can u provide the SpGridView markup? – Thomson Aug 26 '10 at 10:26
Thanks for the response, Thomson. Since I couldn't add large comment, I've edited the question to provide some pseudo code to explain better. Basically, this is a web control without an ascx; it only has the C# code and it is creating the grid view, the data table it binds with, etc. in C# code itself. – Anonymous Aug 27 '10 at 17:36

There is a property called DataKeys

share|improve this answer
Thank you. That sounds like the answer I am looking for; however, it doesn't seem to be working for me. I've set the DataKeyNames property to have 2 fieldnames from my datatables; but the __doPostBack link hasn't changed and still has row index as the parameter to the link. I could be doing something wrong - I'll take some more time and diagnose my code later; for now I've a hacky solution to manipulate the __doPostBack params via jquery. – Anonymous Sep 10 '10 at 17:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.