如何向数据网格对象添加按钮列

问题描述 投票:0回答:1
javascript aspxgridview
1个回答
0
投票

如何将按钮列添加到网格中:

<Columns>
    <asp:TemplateField HeaderText="Actions">
        <ItemTemplate>
            <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="EditRow" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

在您的 aspx.cs 文件中,您需要处理命令。您可以使用 IskurGridView 的 RowCommand 事件来执行此操作:

protected void ctlGridSgkTecrube_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "EditRow")
    {
        // Handle edit logic
        int rowIndex = Convert.ToInt32(e.CommandArgument);
        // Access data for the selected row
    }
    else if (e.CommandName == "DeleteRow")
    {
        // Handle delete logic
        int rowIndex = Convert.ToInt32(e.CommandArgument);
        // Delete data for the selected row
    }
}

记住将 RowCommand 事件处理程序添加到您的 IskurGridView:

<iskurControls:IskurGridView runat="server"
    ID="ctlGridSgkTecrube"
    AutoGenerateColumns="False"
    OnRowCommand="ctlGridSgkTecrube_RowCommand"
    <!-- ... -->
>
    <!-- Columns definition -->
</iskurControls:IskurGridView>
© www.soinside.com 2019 - 2024. All rights reserved.