Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:

OnInit:
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;
Controls.Add(gridview);

OnLoad:
gridview.DataSource = new DataView(table);
gridview.DataBind();

raja.

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

1 Answer 1

There is a property called DataKeys

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx

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

 
discard

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