Remove the extra columns in gridView

Hi

I want to ask how to remove the extra columns in gridView ?

    <asp:GridView ID="gridviewStatusList" runat="server"
          AutoGenerateEditButton="True" onrowediting="GridViewStatusList_RowEditing"
        onrowcancelingedit="GridViewStatusList_RowCancelingEdit"
        onrowupdating="GridViewStatusList_RowUpdating"
        onselectedindexchanged="gridviewStatusList_SelectedIndexChanged">
        <Columns>
            <asp:TemplateField HeaderText="Status ID">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("statusID") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("statusID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="status Description">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server"
   Text='<%# Bind("statusDescription") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("statusDescription") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Status Rank">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("statusRank") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("statusRank") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

hi you can use this code to remove the extra columns in grid view.

void gvAllGeography_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowIndex == -1)

{

e.Row.Cells.RemoveAt(12);

e.Row.Cells.RemoveAt(11);

e.Row.Cells.RemoveAt(10);

e.Row.Cells.RemoveAt(9);

e.Row.Cells.RemoveAt(8);

e.Row.Cells.RemoveAt(7);

e.Row.Cells.RemoveAt(6);

e.Row.Cells.RemoveAt(5);

e.Row.Cells.RemoveAt(4);

//Display the Header Text - Row 1

e.Row.Cells[0].Text = “All Geography”;

e.Row.Cells[1].ColumnSpan = 5;
e.Row.Cells[1].Text = “Executive Summary”;

e.Row.Cells[2].Text = " ";

e.Row.Cells[3].ColumnSpan = 6;
e.Row.Cells[3].Text = “Dealer Status”;

}
}

thanks for help

The extra columns are caused by the gridview auto adding columns from the dataset. All you need to do is add an attribute to the Gridview. AutoGenerateColumns=“false”. This will prevent them from being generated and there will be no need to manually remove them

you need set the property

AutoGenerateColumns="false"

by default it is set to true .
so in your case the columns are auto generated based upon the data in the datasource.
and at the same you are specifying the columns for the gridview. thats the reason you are seeing the extra columns…