【问题标题】:How do I get the current row of a GridView from a Buttonfield click?如何从 Buttonfield 单击获取 GridView 的当前行?
【发布时间】:2009-01-23 17:05:23
【问题描述】:

我有一个带有 DropDownList(在项目模板中)和一个 ButtonField 的 ASP.NET GridView。

<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 指向)设置为下拉列表中的值。请注意,该行不会处于更新模式。

提前致谢!

汤姆

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

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

    来自here

    【讨论】:

    • 有趣。我认为这是由按钮的参数设置的值,而不是行索引。这是默认的吗?
    • 如果您查看呈现的 HTML,我相信他们使用具有特定命名约定的 id 来确定按下了哪个按钮,这将映射回该行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多