C# 如何从Buttonfield单击中获取GridView的当前行?
我有一个ASP.NET GridView,其中有一个DropDownList(在项目模板中)和一个ButtonFieldC# 如何从Buttonfield单击中获取GridView的当前行?,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个ASP.NET GridView,其中有一个DropDownList(在项目模板中)和一个ButtonField <my:GridView AutoGenerateColumns="false" ID="CurrentCardGrid" UseHighlights="False" runat="server" Width="100%"> <Columns> <asp:BoundField HeaderText="ID" ItemStyle-Width=
<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>
在代码中,我填充下拉列表并捕获RowCommand事件
我的问题是,在RowCommand事件处理程序中,如何获取当前行?我需要从下拉列表中获取值,并将行的状态(由ID指向)设置为下拉列表中的值。注意,该行将不会处于更新模式
提前谢谢
Tom在事件处理程序中将e.CommandArgument强制转换为int
从有趣。我认为它是由按钮的参数设置的值,而不是行索引。这是默认值吗?如果您查看呈现的HTML,我相信他们使用具有特定命名约定的id来确定按下了哪个按钮,这将映射回该行。