C# 编辑数据网格视图的一列
我知道如何在数据网格视图中编辑整行,我想知道如何只编辑一列,保持其余数据不变。下面给出了我的当前代码,我想知道如何编辑一列并将该数据更新到数据表中。我只想编辑“ab”列 HTML代码C# 编辑数据网格视图的一列,c#,gridview,datatable,C#,Gridview,Datatable,我知道如何在数据网格视图中编辑整行,我想知道如何只编辑一列,保持其余数据不变。下面给出了我的当前代码,我想知道如何编辑一列并将该数据更新到数据表中。我只想编辑“ab”列 HTML代码 <asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True" OnRowEditing="Gridview1_rowediting" OnRowUpdating="
<asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True"
OnRowEditing="Gridview1_rowediting"
OnRowUpdating="Gridview_RowUpdating"
OnRowCancelingEdit="Gridview_EditCanceling" >
</asp:GridView>
我在我的一个应用程序中尝试了这段代码
foreach (DataGridViewRow c in this.DataGrid.Rows)
c.Cells[0].Value = "Something";
这里“0”是列索引。现在,您可以根据需要设置条件。您可以在“设计”视图中将列ReadOnly设置为True,或通过如下代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
add();
}
//If you are using template field
((TemplateField)gvGridView.Columns[index]).EditItemTemplate = null;
//If you are using boundfield
((BoundField)gvGridView.Columns[index]).ReadOnly = true;
}
或者,可以在设计视图中将该列的编辑模板转换为模板时删除该列的编辑模板
有关详细信息,请查看此链接:
当您在GridView中声明要显示的列时,您可以使用属性“ReadOnly”。是的,但是cnt be CHNAGED我已经尝试过了,它不允许我通过浏览器编辑代码尝试此链接:和
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
add();
}
//If you are using template field
((TemplateField)gvGridView.Columns[index]).EditItemTemplate = null;
//If you are using boundfield
((BoundField)gvGridView.Columns[index]).ReadOnly = true;
}