【问题标题】:Editable grid in ASP.netASP.net 中的可编辑网格
【发布时间】:2013-02-27 18:31:01
【问题描述】:

我正在寻找 ASP.net 可编辑网格视图的代码。
在一些网站上,我得到了编码。但它有一个额外的按钮,如编辑或更新。单击该按钮后,网格变为可编辑的。你可以看到它here

但是当我单击网格的单元格时,我希望网格能够得到编辑。我不想要额外的按钮来点击然后进行编辑。

那么如何让网格只需单击即可编辑呢?

【问题讨论】:

    标签: asp.net gridview datagrid grid


    【解决方案1】:

    您需要使用GridViewRowDataBound 事件来实现此目的。我已经写了一个示例,说明如何做到这一点。根据您的要求进行更改。

    <asp:GridView runat="server" ID="gv" onrowdatabound="gv_RowDataBound" 
                  onrowediting="gv_RowEditing">
    </asp:GridView>
    

    代码隐藏将如下所示:

    private void LoadGrid()
    {
        gv.DataSource = YourDataSource;
        gv.DataBind();
    }
    
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gv, "Edit$" + e.Row.RowIndex);
    
        }
    }
    
    protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gv.EditIndex = e.NewEditIndex;
        this.LoadGrid();  
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 2011-04-30
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多