0
我正在寻找ASP.net可编辑网格视图的代码。
在一些网站我得到了编码。但它有一个额外的按钮,如编辑或更新。点击该按钮时,网格变为可编辑。你可以看到它here。
但我希望网格在单击网格单元格时进行编辑。我不需要额外的按钮来点击然后编辑。
那么如何才能使网格可编辑只需点击它?ASP.net中的可编辑网格
我正在寻找ASP.net可编辑网格视图的代码。
在一些网站我得到了编码。但它有一个额外的按钮,如编辑或更新。点击该按钮时,网格变为可编辑。你可以看到它here。
但我希望网格在单击网格单元格时进行编辑。我不需要额外的按钮来点击然后编辑。
那么如何才能使网格可编辑只需点击它?ASP.net中的可编辑网格
您需要使用
GridView
的RowDataBound
事件来实现此目的。我写了一个你如何做的例子。改变你的要求。
<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();
}