views:

767

answers:

1

I have an ASP.NET GridView with a DropDownList (in an Item Template) and a ButtonField.

<my:GridView AutoGenerateColumns="false" ID="CurrentCardGrid" UseHighlights="False" runat="server" Width="100%">
 <Columns>
  <asp:BoundField HeaderText="ID" ItemStyle-Width="50px" DataField="Id" />
  <asp:TemplateField HeaderText="" ItemStyle-Width="150px">
   <ItemTemplate>
    <asp:DropDownList runat="server" ID="StatusList" Width="140px">
    </asp:DropDownList>
   </ItemTemplate>
  </asp:TemplateField>
  <asp:ButtonField Text="Update" ButtonType="Button" CommandName="Update" />
 </Columns>
</my:GridView>

In code, I fill the drop list and capture the RowCommand event.

My question is, in the RowCommand event handler, how do I get the current row? I need to get the value from the drop list and set the status of the row (pointed to by the ID) to the value from the drop list. Note, the row will not be in update mode.

Thanks in advance!

Tom

+1  A: 

Cast e.CommandArgument to an int in the event handler.

From here

Jason Punyon
Interesting. I thought it was a value set by a parameter of the button, not the row index. Is that the default?
Tom Moseley
If you look at the rendered HTML I believe they use id with a certain naming convention to determine which button was pressed, this is mapped back to the row.
Jason Punyon