Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

You might have to set autogeneratecolumn to false for the gridview

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top