GridView 显示完整的数据源以及 BoundFields
我想要做的只是在 gridview 上显示数据源中的一些特定列,但由于某种原因,我首先看到我想要的绑定字段,然后是数据源中的每一列。
<asp:GridView DataSourceId="dsTasks" ID="TasksGridView" runat="server">
<Columns>
<asp:BoundField DataField="field1" HeaderText="field1" />
<asp:BoundField DataField="field2" HeaderText="field2" />
<asp:BoundField DataField="field3" HeaderText="field3" />
<asp:BoundField DataField="field4" HeaderText="field4" />
<asp:BoundField DataField="field5" HeaderText="field5" />
<asp:BoundField DataField="field6" HeaderText="field6" />
<asp:BoundField DataField="field7" HeaderText="field7" />
</Columns>
</asp:GridView>
这是我的数据源代码,以防万一,
<asp:EntityDataSource ID="dsTasks" runat="server"
ConnectionString="name=Entities" DefaultContainerName="Entities"
EnableFlattening="false" EntitySetName="Tasks" ></asp:EntityDataSource>
抱歉,如果这是一个愚蠢的问题...我对.NET总体来说还很陌生(尝试一周)
另外,作为一个附带问题,会吗?以这种方式绑定数据对我来说更好,还是在 page_load 的代码隐藏中进行?
What I want to do is just display a few specific columns from my data source on my gridview, but for some reason I'm seeing first the boundfields that I want, followed by every column in the data source.
<asp:GridView DataSourceId="dsTasks" ID="TasksGridView" runat="server">
<Columns>
<asp:BoundField DataField="field1" HeaderText="field1" />
<asp:BoundField DataField="field2" HeaderText="field2" />
<asp:BoundField DataField="field3" HeaderText="field3" />
<asp:BoundField DataField="field4" HeaderText="field4" />
<asp:BoundField DataField="field5" HeaderText="field5" />
<asp:BoundField DataField="field6" HeaderText="field6" />
<asp:BoundField DataField="field7" HeaderText="field7" />
</Columns>
</asp:GridView>
and here is my code for the datasource, just in case thats where it is
<asp:EntityDataSource ID="dsTasks" runat="server"
ConnectionString="name=Entities" DefaultContainerName="Entities"
EnableFlattening="false" EntitySetName="Tasks" ></asp:EntityDataSource>
Sorry if this is a stupid question...I'm fairly new to .NET in general (try a week)
Also, as a side question, would it be better for me to bind the data this way, or do it in the code-behind on page_load?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置
AutoGenerateColumns
到false
就我个人而言,我更喜欢在可能的情况下通过标记进行绑定,而不是通过代码进行绑定。
Set
AutoGenerateColumns
tofalse
Personally, I prefer binding from markup than from code when and where it's possible.
您可能必须将 gridview 的 autogeneratecolumn 设置为 false
You might have to set autogeneratecolumn to false for the gridview