【问题标题】:Get hidden value on row deleting event in datagrid (ASP Webforms)获取数据网格中行删除事件的隐藏值(ASP Webforms)
【发布时间】:2013-08-17 05:30:52
【问题描述】:

我无法从 datagrid 检索不可见列的值。如果列不可见,如何获取值?

这是我的代码:

数据网格:

<asp:BoundField DataField="id" HeaderText="ID" ReadOnly="True" 
            Visible="False" />
        <asp:BoundField DataField="category" HeaderText="Category" />
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ShowHeader="True" />

行删除事件

 protected void dgvCategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = dgvCategory.Rows[e.RowIndex].Cells[0].Text;

        string name = dgvCategory.Rows[e.RowIndex].Cells[1].Text;

        runDelete(id, name);

        loadDataCategory();            

    }

我该如何解决我的问题?

【问题讨论】:

    标签: c# asp.net datagrid


    【解决方案1】:

    您可以将此 ID 列添加为 DataKey

    在你的 aspx 中

    <asp:GridView DataKeyNames="id" ....
    

    在你的活动中

    protected void dgvCategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        var key = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
    }
    

    其他选项是使用 css 样式隐藏列

    使用display: none; 创建新的css 类并将其应用于BoundFieldItemStyle-CssClassHeaderStyle-CssClass。删除 Visible="False" 属性。

    现在您可以获取其他列的值,但它不会显示在客户端 UI 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2013-10-19
      • 2012-07-17
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      相关资源
      最近更新 更多