0
votes

I have the following in an ASP.NET GridView:

<asp:TemplateField>
  <ItemTemplate>

    <asp:ImageButton ID="ibtnDown" runat="server" ToolTip="Down" CommandName="Down" 
      ImageUrl="~/images/arrow.png" Width="16px" Height="16px" 
      CommandArgument="<%# Container.DataItemIndex %>" />

  </ItemTemplate>
</asp:TemplateField>

It's simply an image button that when clicked raises the RowCommand event for the GridView. It is very convenient in that it allows me to use the CommandName and CommandArgument in order to determine the button that was clicked and for which row it was clicked.

However, I find that the .NET ImageButton is limited in that it can't display CSS sprites in order to change the image on mouseover. At least I couldn't get it to work, but of course that doesn't preclude some manner in which it's possible.

Anyway, I'd like to use a standard HTML button tag because I know how to get it to work with my sprites.

<button name="btnDown" id="btnDown" type="submit" class="downArrow"></button>

But what I don't know how to do is get the button to cause a postback and raise the RowCommand event and still allow me to somehow access the CommandArgument and CommandName parameters.

3

3 Answers

1
votes

Right I would make the button a server control first, then use its various properties as an alternative to commandName and CommandArgument. Additionally I would use OnServerClick event in place of rowCommand. I would use at last the sender object parse it to an hmt button and extract the values out of its properties. I think I'vent got lost.

<button runat="server" name="Down" id="btnDown" title="<%# Container.DataItemIndex %>" type="submit" class="downArrow" OnServerClick="ClickMe"></button
1
votes

Have you considered using a button field to perform the action you wish to do?

Take a look at the following link ButtonFields within a GridView

1
votes

Just use (original post here):

<asp:LinkButton ID="LinkButton1" runat="server">
    <div class="sprite-box_mac_osx_disc_button" />
</asp:LinkButton> 

Of course use your own css with all width, height, background and background-position. And add Command and CommandArgument to LinkButton.