0

我有一个 GridView 控件,它列出了具有以下字段的客户对象:
ID、FirstName、LastName 和 SignUpDate。

我需要向允许我
编辑特定客户的 GridView 控件添加第五列(“编辑”)。它可以是 LinkBut​​ton 或 BoundButton。

因此,当单击“编辑”链接/按钮时,我想访问 Id 并将其传递
给 Click 事件。我有一个方法,它需要一个 Id 并编辑客户。

GridView 绑定到一个客户对象列表。我怎样才能做到这一点?

<asp:GridView ...>
    <Columns>
        <asp:ButtonField HeaderText="Customer ID"  DataTextField="Id" />
        <asp:ButtonField HeaderText="First Name"   DataTextField="FirstName" />
        <asp:ButtonField HeaderText="Last Name"    DataTextField="LastName" />
        <asp:ButtonField HeaderText="Member Since" DataTextField="SignUpDate" />
        <'Edit' link/button here. Want to pass 'Id' to a method when clicked />
    </Columns>
</asp:GridView>

customerList.DataSource = customerList; // this is List<Customer>
customerList.DataKeyNames = new string[] {"Id"};
customerList.DataBind();
4

1 回答 1

0

You need to add a commandfield to define your edit column.

<asp:CommandField ShowEditButton="True" />
于 2013-01-27T20:32:10.903 回答