开发者

GridView showing complete datasource as well as BoundFields

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>
开发者_JAVA百科

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?


Set AutoGenerateColumns to false

<asp:GridView AutoGenerateColumns="false" DataSourceId="dsTasks" ...

Personally, I prefer binding from markup than from code when and where it's possible.


You might have to set autogeneratecolumn to false for the gridview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜