Sreedhar Danturthi
Sreedhar Danturthi

Reputation: 7601

problem with display of gridview in asp.net

I'm displaying a GridView using the following markup in my default.aspx:

<Columns>
  <asp:BoundField DataField="SNo" HeaderText="SNo" />
  <asp:BoundField DataField="ComponentName" HeaderText="Component Name" />
  <asp:BoundField DataField="Size" HeaderText="Size" />
  <asp:BoundField DataField="price" HeaderText="Price" />
  <asp:BoundField DataField="TotalDownloads" HeaderText="Total Downloads" />
  <asp:BoundField DataField="Description" HeaderText="Description" />
</Columns>

In the codebehind default.aspx.cs I have:

var result = (from Component comp in db 
              orderby comp.SNo 
              select new { 
                  SNo = comp.SNo, 
                  ComponentName = comp.ComponentName, 
                  Size = comp.Size, 
                  Price = comp.Price, 
                  TotalDownloads = comp.TotalDownloads, 
                  Description = comp.Description 
               }).ToList();

ComponentGridView.DataSource = result;
ComponentGridView.DataBind();

But the GridView looks like this:

enter image description here

I don't understand this. Why am I getting the same columns rendered twice?

Upvotes: 1

Views: 358

Answers (3)

John Batdorf
John Batdorf

Reputation: 2542

Set autogenerateColumns = false;

Upvotes: 1

David
David

Reputation: 219096

If you're manually handling the columns, is AutoGenerateColumns set to false?

Upvotes: 2

dugas
dugas

Reputation: 12493

Set AutoGenerateColumns = "False" on your GridView

Upvotes: 4

Related Questions