Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP:DataGrid显示列两次_C#_Asp.net_Datagrid - Fatal编程技术网

C# ASP:DataGrid显示列两次

C# ASP:DataGrid显示列两次,c#,asp.net,datagrid,C#,Asp.net,Datagrid,我想在我的DataGrid对象中绑定列。代码在我添加它们之前运行得很好,但是现在我得到了重复的列,特别是一个我根本不想要的列。以下是ASP: <ASP:DataGrid id="UserDataGrid" AutoGenerateColums="False" runat="server"> <Columns> <asp:EditCommandColumn CancelText="Cancel"

我想在我的
DataGrid
对象中绑定列。代码在我添加它们之前运行得很好,但是现在我得到了重复的列,特别是一个我根本不想要的列。以下是ASP:

        <ASP:DataGrid id="UserDataGrid" AutoGenerateColums="False" runat="server">
            <Columns>
                <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update" HeaderText="Edit item">
                    <ItemStyle Wrap="False" />
                    <HeaderStyle Wrap="False"/>
                </asp:EditCommandColumn>
                <asp:BoundColumn DataField="Email" HeaderText="Email" ReadOnly="false" SortExpression="Email" />
                <asp:BoundColumn DataField="UserID" HeaderText="User ID" ReadOnly="false" SortExpression="UserID" />
                <asp:BoundColumn DataField="FullName" HeaderText="User Name" ReadOnly="false" SortExpression="FullName" />
            </Columns>
        </ASP:DataGrid>

我读到的所有内容都说,将
AutoGenerateColumns
设置为false应该可以解决问题,但它没有起到任何作用。

查看您提供的代码,
AutoGenerateColumns
似乎拼写不正确。如果你能修好的话,它应该可以正常工作

<asp:DataGrid ID="UserDataGrid" AutoGenerateColumns="false" runat="server">

解决方案:1

通常,autogeneratecolumns属性为true,如果我们将DataGrid绑定到表,DataGrid将显示表中的所有列。只有当您将autogeneratecolumns设置为false时,才可以让DataGrid显示您指定的列

但据你说,这是行不通的,好吗

解决方案:2

可以隐藏DataGrid列

 DataTable dtUsers = new DataTable();
    dtUsers = dataAccessManager.ExecuteSQLForTable("SELECT * FROM tblUser");
    UserDataGrid.DataSource = dtUsers;
    UserDataGrid.DataBind();
    //Right Below line for hide columns
    UserDataGrid.Columns[0].Visible = false;//Hide First column of the DataGrid 
    UserDataGrid.Columns[1].Visible = false;//Hide Second column of the DataGrid 
    UserDataGrid.Columns[2].Visible = false;//Hide Third column of the DataGrid 
 DataTable dtUsers = new DataTable();
    dtUsers = dataAccessManager.ExecuteSQLForTable("SELECT * FROM tblUser");
    UserDataGrid.DataSource = dtUsers;
    UserDataGrid.DataBind();
    //Right Below line for Remove columns

    UserDataGrid.Columns[0].Remove(); //Remove First column of the DataGrid 
    UserDataGrid.Columns[1].Remove(); //Remove Second column of the DataGrid 
    UserDataGrid.Columns[2].Remove(); //Remove Third column of the DataGrid 
解决方案:3

您可以删除DataGrid列

 DataTable dtUsers = new DataTable();
    dtUsers = dataAccessManager.ExecuteSQLForTable("SELECT * FROM tblUser");
    UserDataGrid.DataSource = dtUsers;
    UserDataGrid.DataBind();
    //Right Below line for hide columns
    UserDataGrid.Columns[0].Visible = false;//Hide First column of the DataGrid 
    UserDataGrid.Columns[1].Visible = false;//Hide Second column of the DataGrid 
    UserDataGrid.Columns[2].Visible = false;//Hide Third column of the DataGrid 
 DataTable dtUsers = new DataTable();
    dtUsers = dataAccessManager.ExecuteSQLForTable("SELECT * FROM tblUser");
    UserDataGrid.DataSource = dtUsers;
    UserDataGrid.DataBind();
    //Right Below line for Remove columns

    UserDataGrid.Columns[0].Remove(); //Remove First column of the DataGrid 
    UserDataGrid.Columns[1].Remove(); //Remove Second column of the DataGrid 
    UserDataGrid.Columns[2].Remove(); //Remove Third column of the DataGrid 

最美好的祝愿

这么多的掌心人。我以为VS2010会抱怨与类不匹配的属性?