【发布时间】:2014-04-03 07:38:35
【问题描述】:
我在 gridview 项目模板中有图像按钮。在 RowCommand 事件中单击该图像时,CommandName 显示的结果与我的预期不同。它总是说“选择”,但我期待“pdf”。
这只发生在 IE 中。不是 Chrome。
<asp:GridView ID="grdLoan" Width="100%" runat="server" CssClass="grid" HeaderStyle-CssClass="gridHeader"
PageSize="25" AutoGenerateColumns="false" RowStyle-CssClass="gridItem" AlternatingRowStyle-CssClass="gridAltItem"
AllowPaging="false" BackColor="LightGray">
<SelectedRowStyle CssClass="SelectedRowStyle" />
<Columns>
<asp:BoundField HeaderText="Loan Number" DataField="strAltLoanNumber">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="Security" DataField="strGlobalSecurity">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="Sample #" DataField="intSampleID"></asp:BoundField>
<asp:TemplateField HeaderText="PDF">
<ItemTemplate>
<asp:ImageButton CommandName="pdf" ID="imgPDF" ImageUrl="~/Images/pdf.png" runat="server"
CommandArgument='<%#Eval("strGlobalLoanNumber")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Gridview 事件
Private Sub grdLoan_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles grdLoan.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';"
e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';"
e.Row.ToolTip = "Click to select row"
e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(Me.grdLoan, "Select$" & e.Row.RowIndex)
End If
End Sub
Private Sub grdLoan_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grdLoan.RowCommand
If e.CommandName = "pdf" Then
end if
End sub
我也试过了
<asp:ImageButton CommandName="pdf" ID="imgPDF" ImageUrl="~/Images/pdf.png"
runat="server" CommandArgument='<%#Eval("strNumber")%>' OnClick="imgPDF_Click" />
Onclick 事件永远不会触发,Chrome 会正常工作。
也试过了
<asp:CommandField ShowEditButton ...>
第一次RowCommand 发射两次。一次是Edit,另一个是select。如果我第二次点击它是Select。
我不明白发生了什么。
【问题讨论】:
-
你试过我关于“Page_Load”的回答了吗?
标签: c# asp.net vb.net gridview