在 ASP.NET Web Forms 中,可以通过 GridView 的 RowCommand 事件获取当前行的数据。具体步骤如下:

  1. 在 GridView 控件上设置 RowCommand 事件处理程序:

    <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">
    </asp:GridView>
    
  2. 在代码文件中编写 RowCommand 事件处理程序:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        // 获取当前行的索引
        int rowIndex = Convert.ToInt32(e.CommandArgument);
    
        // 根据索引获取当前行的数据
        GridViewRow row = GridView1.Rows[rowIndex];
        string data = row.Cells[0].Text; // 假设需要获取第一列的数据
    }
    

在 RowCommand 事件处理程序中,可以通过 e.CommandArgument 获取当前行的索引,然后使用索引访问 GridView 的 Rows 集合获取当前行的 GridViewRow 对象。然后可以使用 GridViewRow 的 Cells 集合获取当前行的单元格数据

aspnet web 在 GridView如何获得当行的数据

原文地址: https://www.cveoy.top/t/topic/iQcv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录