I've looked at pages and pages of documentation and forum threads, but I can't seem to get around this issue. Using the WebDataGrid (.NET 3.5) I have a grid with nine or so templated columns. The first column template is a LinkButton; I have that set up for an ItemCommand to process it (gets the detail data and displays it on another web page). I have my CommandName set up, and what I need to do is either pass the container for that row, or the row index, back to the server side ItemCommand method so I can grap some other fields from that row. Basically, in ItemCommand I need to know what row that LinkButton was clicked.
I've tried everything to get the CommandArgument to pass back the record number but nothing works. I tried the idea presented in another thread, using:
CommandArgument="<%# Container.Cell.Row.Index %>"
but that always gives back the error 'Cell' is not a member of 'System.Web.UI.Control'.
So my big question is: In ItemCommand (for a WebDataGrid) how can I either get the current row that the LinkButton was click on (in ItemCommand), or at least get passed back the row index?
I'm frustrated... hope someone can help. Thx.
/Tom
I agree. You should be able to reference the row in question. Passing multiple values in the CommandArgument field is not always feasible. You would want to be able to reference the Grid row and the Data row behind it. If this is not possible, then simply tell us.
The Container needs to be cast to Infragistics.Web.UI.TemplateContainer. You can either store in the CommandArgument a unique identifier of the row, like a data key for example (here DataItem should be used)
CommandArgument=<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "PostId") %>
or reference the actual underlying object. In case of the ItemTemplate it is the cell. To get the row index, something like that can be done (here the Item property should be used):
CommandArgument=<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).Item, "Row.Index") %>
This latter approach however has a problem, the Item property is currently referencing the same object as the DataItem. It's been fixed and the fix is coming up shortly.
But when I used this
I get an error
'TemplateContainer' is a type in 'UI' and cannot be used as an expression.
please suggest solution.
Are you using VB?