GridView template needs to set CommandArgument to row index

D

David

I have a template field in a GridView that contains two ImageButtons.
When the user clicks one of the buttons, the GridView's RowCommand
event is fired and I can get the CommandName. All that is fine.
However, e.CommandArgument is an empty string, presumably because the
CommandArgument property of the ImageButtons is not set.

Is there some way, in the markup, to set the CommandArgument to the row
index?

<ItemTemplate>
<asp:ImageButton ID="btnSave" runat="server"
CommandName="Save" ImageUrl="~/Images/Diskette.gif"
CommandArgument="SOMETHING HERE" />&nbsp;&nbsp;
<asp:ImageButton ID="Email" runat="server"
CommandName="Email" ImageUrl="~/Images/Envelope.gif"
CommandArgument="SOMETHING HERE" />
</ItemTemplate>

TIA,

David
 
D

David

Thank you for your reply. I had already planned on doing it in the
RowCreated event. I was just hoping there was some way to do it in the
markup.

Thanks again.

David
 
Joined
Nov 22, 2006
Messages
1
Reaction score
0
There is a way to do it using the markup:

<asp:Button (...) CommandArgument="<%# Container.DataItemIndex %>" />
 
Joined
Jun 19, 2007
Messages
1
Reaction score
0
mcalmeida said:
There is a way to do it using the markup:

<asp:Button (...) CommandArgument="<%# Container.DataItemIndex %>" />
Thank you so much! I've been fighting with the empty string trying to convert itself all afternoon. :mrgreen:
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top