views:

40

answers:

4

I have a list of objects called Activity and I want to display the date, type and notes for each and every one of these activities. This is the code I'm using.

<asp:GridView ID="gvTable" runat="server" AllowSorting="true" ShowHeader="true">
  <Columns>
    <asp:BoundField DataField="ActivityDate" HeaderText="Date"
      HeaderStyle-CssClass="date" />
    <asp:BoundField DataField="ActivityType" HeaderText="Type" />
    <asp:BoundField DataField="ActivityNotes" HeaderText="Notes" />
  </Columns>
  <PagerSettings Position="Bottom" Mode="NextPrevious" PageButtonCount="5"
    PreviousPageText="Older activities" NextPageText="Newer activities" />
</asp:GridView>

However, all of the attributes of each object is displayed in the header. How can I force it to display only the columns that I want to use?

+2  A: 

gvTable.AutoGenerateColumns = False

or

<asp:GridView ID="gvTable" runat="server" AutoGenerateColumns="False" AllowSorting="true" ShowHeader="true">

should do the trick.

Shawn Steward
+1  A: 

You need to set the AutoGenerateColumns property on the grid to false.

Paddy
+2  A: 

Set the attribute on your gridview:

AutoGenerateColumns="false"
Kelsey
+1  A: 

Have you tried AutoGenerateColumns="false" in the gridview?

adrianos