在asp.net中显示gridview的问题

时间:2011-04-09 22:55:58

标签: asp.net gridview

我在GridView中使用以下标记显示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>

在代码隐藏default.aspx.cs我有:

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();

但是GridView看起来像这样:

enter image description here

我不明白这一点。为什么我得到两次相同的列?

3 个答案:

答案 0 :(得分:4)

在GridView上设置AutoGenerateColumns =“False”

答案 1 :(得分:2)

如果您手动处理列,AutoGenerateColumns设置为false

答案 2 :(得分:1)

设置autogenerateColumns = false;