我知道如何在数据网格视图中编辑整行,我想知道如何仅编辑一列以保持其余数据相同。我的当前代码如下所示,我想知道如何仅编辑一列并将该数据更新到数据表中。我只想编辑“ab”列。
代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True"
OnRowEditing="Gridview1_rowediting"
OnRowUpdating="Gridview_RowUpdating"
OnRowCancelingEdit="Gridview_EditCanceling" >
</asp:GridView>
后面的 C# 代码
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
add();
}
}
private void add()
{
dt.Columns.Add("ab", typeof(string));
dt.Columns.Add("ac", typeof(string));
dt.Columns.Add("av", typeof(string));
dt.Columns.Add("ax", typeof(string));
DataRow row = dt.NewRow();
row["ac"] = "sndasbfb";
row["av"] = "sndasbfb";
row["av"] = "sndasbfb";
row["ax"] = "sndasbfb";
dt.Rows.Add(row);
GridView1.DataSource = dt;
//ProjectsGridView.DataSource = dt;
//ReleasesGridView.DataSource = dt;
GridView1.DataBind();
// ProjectsGridView.DataBind();
// ReleasesGridView.DataBind();
}
protected void Gridview1_rowediting(object sender, GridViewEditEventArgs e)
{
//GridView1.EditIndex = e.NewEditIndex;
}
protected void Gridview_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
}
protected void Gridview_EditCanceling(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
add();
}