开发者

ASP.NET/GridView: Using only a subset of the data fields in the table

开发者 https://www.devze.com 2022-12-14 19:11 出处:网络
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.

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="T开发者_Python百科ype" />
    <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?


gvTable.AutoGenerateColumns = false

or

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

should do the trick.


Set the attribute on your gridview:

AutoGenerateColumns="false"


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


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

0

精彩评论

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