Ofer Gozlan
Ofer Gozlan

Reputation: 1143

Multiple asp:CommandField(s) at the same cell

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!!!

Upvotes: 0

Views: 335

Answers (2)

DaniDev
DaniDev

Reputation: 2631

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)
{

}

Upvotes: 0

Struggling
Struggling

Reputation: 51

Try asp:TemplateField

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

Upvotes: 0

Related Questions