gridview自定义列的方法是什么

要自定义GridView的列,通常需要使用TemplateField或BoundField。在TemplateField中,可以定义列的显示方式,并在里面添加控件或HTML标记。在BoundField中,可以定义列的数据绑定方式和显示格式。以下是一个简单的示例:

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:BoundField DataField="ProductName" HeaderText="Product Name" />
        <asp:TemplateField HeaderText="Price">
            <ItemTemplate>
                $<%# Eval("Price") %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Edit">
            <ItemTemplate>
                <asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

在这个示例中,GridView包含三列:ProductName列使用BoundField显示数据,Price列和Edit列使用TemplateField自定义显示方式。可以根据需要在TemplateField中添加不同的控件或样式来自定义列的显示。

Both comments and pings are currently closed.

Comments are closed.

Powered by KingAbc | 粤ICP备16106647号-2 | Loading Time‌ 0.279