SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    remove the extra columns in gridView

    Hi

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

    HTML Code:
        <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>
    Capture.PNG

  2. #2
    SitePoint Member
    Join Date
    May 2012
    Location
    USA
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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";


    }
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for help

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    you need set the property
    Code ASP:
    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..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •