我在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
看起来像这样:
我不明白这一点。为什么我得到两次相同的列?
答案 0 :(得分:4)
在GridView上设置AutoGenerateColumns =“False”
答案 1 :(得分:2)
如果您手动处理列,AutoGenerateColumns设置为false
?
答案 2 :(得分:1)
设置autogenerateColumns = false;