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. However, every column is shown twice (Pic) in the GridView!
I have declared the columns only once, so why are the columns shown twice, and how can I fix this?
My code is 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>
Code-behind:
objVendor = client.GetAllVenorsForPCMS();
if (objVendor.Count > 0){
gvVendorsDetails.DataSource = objVendor;
gvVendorsDetails.DataBind();
}
else{
gvVendorsDetails.DataSource = null;
gvVendorsDetails.DataBind();
}
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, it 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>
...
</asp:GridView>