我用Visual studio直接配置一个GridView,并添加一个CommandField,将其设为可编辑。然后我写代码向该列添加数据,结果Gridview又多出来一列。麻烦大家看看我的代码,我希望向可编辑列中添加一个数据“编辑测试”。但运行后发现GridView一下子变成2列了,第一列显示“Edit”且可编辑,第二列显示“编辑测试”但数据不能编辑。
请问要如何修改才能让这一列设为可编辑.aspx配置代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestGridView.Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:CommandField ShowEditButton="True" />
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>.cs代码:        private void GridViewBind()
        {
            List<string> test = new List<string>();            test.Add("编辑测试");            GridView1.DataSource = test;
            GridView1.DataBind();
        }

解决方案 »

  1.   

    MS都可以编辑。是不是少写了什么例如:<EditItemTemplate>xxxxxxx</EditItemTemplate>
    http://phigo.bokee.com/6729703.html参考
      

  2.   

    谢谢您的提醒.我现在的问题是不知道如何向可编辑列添加数据,我自己写一个LIST然后绑定,结果这个LIST中的数据没有添加进EDIT这列,而是另外成了一个新列,请问这个如何处理.
      

  3.   

    自己搞定了,EditField貌似不能编辑,要添加可编辑列,要么用模板插入TEXTBOX,要么新建一列,在点EDIT后直接编辑该列.
    另外,DATATABLE里的列名要与DATAFIELD的数据相同才能正确插入数据,同时把AUTOGENERATECOLUMN设置为FALSE.