6

次のようなオブジェクトがあります。

public class TestData
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
    public string Email {get; set;}
    public string Phone {get; set;}
}

そのクラスの 10 個のインスタンスが に格納されていIENumerableます。

GridView私のファイルにもありaspxます:

<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

私が必要としているのは、の内容を表示する方法IENumerableですGridViewtheadしかし、テーブルの「タイトル」を自分で設定できるようにしたいです。

だから私はこのようなものを得る:

<table>
  <thead>
    <th>Firstname</th>
    <th>Firstname</th>
    <th>Telephone</th>
    <th>Email address</th>
  </thead>
  <tbody>
    <!-- the values from each TestData class stored in the IENumberable -->
  </tbody>
</table>

でこれを行うことができますか、GridViewそれともジョブに他のコントロールを使用する方が良いですか? テンプレートについて何か覚えていますか?よくわかりませんが、私は ASP.NET にかなり慣れていません。

4

1 に答える 1

5

バインドされたフィールドを明示的HeaderTextに指定してバインドされたフィールドを使用できます。
列の自動生成を false に使用します。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumn="false">
    <asp:BoundField DataField="FirstName" HeaderText="First Name" />
    <asp:BoundField DataField="LastName " HeaderText="Last Name" />
    .....
</asp:GridView>

編集 1

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumn="false">
  <Columns>
    <asp:BoundField DataField="FirstName" HeaderText="First Name" />
    <asp:BoundField DataField="LastName " HeaderText="Last Name" />
    .....
  </Columns>
</asp:GridView>

于 2013-02-21T08:16:39.227 に答える