我想在GridView中显示数据库中的某些字段,但是我的问题是,它在一个新字段中显示了我想要的所有字段,
这是我的代码
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
这是C#代码
GridView1.DataSource = (from x in db.Products
select x.name + x.phoneNumber + x.proviance + x.description + x.city + x.Address).ToList();
GridView1.DataBind();
如何在asp.net显示在C#中的表(不是所有的字段)的某些字段到GridView控件
相对于
因此,默认情况下,GridView会为给定数据集中的所有字段/列生成列。要选择您看到的内容,您需要将其关闭并显式声明所需的列:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="name of the column in the data set"
HeaderField="header to show on the UI"/>
... and so on for other columns ...
</Columns>
</asp:GridView>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句