【发布时间】:2012-01-19 21:05:23
【问题描述】:
我在 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>
它只是一个图像按钮,单击该按钮会引发 GridView 的 RowCommand 事件。这非常方便,因为它允许我使用 CommandName 和 CommandArgument 来确定单击的按钮以及单击的行。
但是,我发现 .NET ImageButton 的局限性在于它无法显示 CSS 精灵来更改鼠标悬停时的图像。至少我无法让它工作,但当然这并不排除它可能的某种方式。
无论如何,我想使用一个标准的 HTML 按钮标签,因为我知道如何让它与我的精灵一起工作。
<button name="btnDown" id="btnDown" type="submit" class="downArrow"></button>
但我不知道该怎么做是让按钮导致回发并引发 RowCommand 事件,但仍然允许我以某种方式访问 CommandArgument 和 CommandName 参数。
【问题讨论】:
标签: asp.net gridview button postback