Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there unwanted duplicated and extra columns in Asp:GridView?

I am trying to show some Details on my Web-Page using the ASP:GridView Control. Accordingly, I have added the columns that I need to show. But, every column is shown twice (Pic) in the GridView . enter image description here

By back end Code is as follows:

objVendor = client.GetAllVenorsForPCMS();

        if (objVendor.Count > 0)
        {

            gvVendorsDetails.DataSource = objVendor;
            gvVendorsDetails.DataBind();

        }

        else
        {
            gvVendorsDetails.DataSource = null;
            gvVendorsDetails.DataBind();
        }

and aspx Code as follows :

                <div align="center" style="border: 1px solid;">
                    <asp:GridView ID="gvVendorsDetails" runat="server" CssClass="mGrid">
                        <Columns>
                            <asp:BoundField HeaderText="Vendor ID" DataField="VendorID" Visible="false" />
                            <asp:BoundField HeaderText="Vendor Name" DataField="VendorName" Visible="true" />
                            <asp:BoundField HeaderText="Vendor Description" DataField="VendorDescription" Visible="true" />
                            <asp:BoundField HeaderText="Address" DataField="Address" Visible="true" />
                            <asp:BoundField HeaderText="City" DataField="City" Visible="true" />
                            <asp:BoundField HeaderText="State" DataField="State" Visible="true" />
                            <asp:BoundField HeaderText="Country" DataField="Country" Visible="true" />
                            <asp:BoundField HeaderText="Contact Person" DataField="ContactPerson" Visible="true" />
                            <asp:BoundField HeaderText="Contact No" DataField="ContactNo" Visible="true" />
                            <asp:BoundField HeaderText="ZIP Code" DataField="ZIPCode" Visible="true" />
                        </Columns>
                    </asp:GridView>
                </div>

I have added the columns only once, but how come in the result columns are shown Twice !! ?

like image 276
Mangesh Kaslikar Avatar asked Dec 20 '22 04:12

Mangesh Kaslikar


1 Answers

A common reason for this is because you also have the AutoGenerateColumns property set to true (which is the default). By setting the property to false will limit the columns generated to just those you have specified explicitly.

i.e. fix this like so:

<asp:GridView ID="gvVendorsDetails" runat="server" 
              CssClass="mGrid" AutoGenerateColumns="False">
     <Columns> ...
like image 134
StuartLC Avatar answered May 20 '23 06:05

StuartLC