custom button/link in detailsview commandfield section

M

mt

Hi,

Is it possible to add a button or a link to to the detailsview commandfield
section (where the new, insert, cancel) buttons are displayed.

I've added a button column to the detailsview but it is displayed on a
separate row. Instead I would like to have this button on the same row as the
command fields.

Any help is appreciated.

Thanks
 
P

Phillip Williams

If you want to customize this row then instead of using the CommandField use
a TemplateField where you define any or all of the ItemTemplate,
EditItemTemplate or InsertItemTemplate as required.

In each template you can add LinkButtons with the desired CommandNames for
each template. For example, within the ItemTemplate, you would add:

<asp:LinkButton Text="Edit" runat="server" ID="Edit"
CommandName="Edit"></asp:LinkButton>
<asp:LinkButton Text="Insert" runat="server" ID="Insert"
CommandName="New"></asp:LinkButton>

In the EditItemTemplate, you would add:

<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="btnCancel" CausesValidation="false" runat="server"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>

and in the InsertItemTemplate you would add:

<asp:LinkButton ID="btnInsert" runat="server" CommandName="Insert"
Text="Insert"></asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>

This would mimic the action performed by the CommandField (which renders all
those buttons for you based on which property you set to true (e.g.
ShowEditButton=true would render the LinkButton with CommandName="Edit" that
we did above)

But by doing this in templates you get the opportunity to customize the
layout of the DetailsView where you can add now within that templateField the
Button or Link that you asked to add.
 
M

mt

Thank you.

Phillip Williams said:
If you want to customize this row then instead of using the CommandField use
a TemplateField where you define any or all of the ItemTemplate,
EditItemTemplate or InsertItemTemplate as required.

In each template you can add LinkButtons with the desired CommandNames for
each template. For example, within the ItemTemplate, you would add:

<asp:LinkButton Text="Edit" runat="server" ID="Edit"
CommandName="Edit"></asp:LinkButton>
<asp:LinkButton Text="Insert" runat="server" ID="Insert"
CommandName="New"></asp:LinkButton>

In the EditItemTemplate, you would add:

<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="btnCancel" CausesValidation="false" runat="server"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>

and in the InsertItemTemplate you would add:

<asp:LinkButton ID="btnInsert" runat="server" CommandName="Insert"
Text="Insert"></asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>

This would mimic the action performed by the CommandField (which renders all
those buttons for you based on which property you set to true (e.g.
ShowEditButton=true would render the LinkButton with CommandName="Edit" that
we did above)

But by doing this in templates you get the opportunity to customize the
layout of the DetailsView where you can add now within that templateField the
Button or Link that you asked to add.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top