ASP.NET 2.0 Tip: How To Get The RowIndex When You Press An ASP:Button in a GridView
Finding out the above took me quite some time. It's not standard behavior to have a gridview with multiple row, with all rows having a configurable number of Textboxes on which data entry can be done, and that stores the data back to the underlying datasource with a 20+ parameter stored procedure, containing all fixed entries from the specific row.
Are you still with me? Well, put a bit simpler, I needed the rowindex of the specific row that was pressed. At first I thought well, that must be Gridview1.Rowindex, wouldn't it? but this turned out to be not the case. That is, the rowindex was not known inside the RowCommand event. After *a lot* of Googling it turned out I needed to add a CommandArgument to the Button, like so:
46 <asp:Button ID="updateDB" runat="server" CausesValidation="false" CommandName="updateDB"
47 CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>" Text="updateDB" />
Simple enough if you've seen it before, but not so obvious to me...
Thanks to an asp.net forum thread and Mr DataAccess in ASP.NET himself Scott Mitchell (at the bottom)
1 Comments:
Perfect, thank you!
Post a Comment
<< Home