代码之家  ›  专栏  ›  技术社区  ›  Tom Moseley

如何从Buttonfield单击中获取GridView的当前行?

  •  1
  • Tom Moseley  · 技术社区  · 16 年前

    我有一个ASP.NET GridView,其中有一个DropDownList(在项目模板中)和一个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>
    

    在代码中,我填充下拉列表并捕获RowCommand事件。

    我的问题是,在RowCommand事件处理程序中,如何获取当前行?我需要从下拉列表中获取值,并将行的状态(由ID指向)设置为下拉列表中的值。注意,该行将不会处于更新模式。

    汤姆

    1 回复  |  直到 16 年前
        1
  •  2
  •   Indeed is Trash    16 年前

    将e.CommandArgument强制转换为事件处理程序中的int。

    从…起 here