Multiple asp:CommandField(s) at the same cell

343 views Asked by At

My asp:GridView has the options to edit / delete rows. I would like those two options to be in the same cell of every row that I have (currently these two options are presented in different cells).

This is the code that I have right now:

<asp:CommandField ShowEditButton='True' edittext='edit' canceltext='cancel' updatetext='update'></asp:CommandField>
<asp:CommandField ShowDeleteButton='True' DeleteText='delete' ></asp:CommandField>  

Any help will be appreciated!!!

2

There are 2 answers

3
Struggling On

Try asp:TemplateField

and put both of your options there? I'm not sure if that will work. But have you tried it?

2
DaniDev On

Try using a template column like this:

<asp:GridView ID="grid" runat="server" OnSelectedIndexChanged="grid_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button id="btnEdit" runat="server" />
                <asp:Button id="btnDelete" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Then you'll have to add the code for your grid_SelectedIndexChanged

protected void grid_SelectedIndexChanged(object sender, EventArgs e)
{

}