我的asp.net应用程序中有一个gridview。我们添加了代码来拦截行中任意位置的行点击。
这完美无缺。只要单击一行,就会触发RowCommand
事件。
(在这种情况下,它将用户重定向到另一个页面)
现在我想添加一个带有Image的列,当单击它时,不应该重定向用户,而是激活一些Javascript。 但是,当javascript被触发时,RowClick也会被触发 有没有办法暂时禁用RowClick?
编辑:更新代码
gridview:
<asp:GridView id="OpleidingView" runat="server" SkinID="sknGridView" ShowHeader="false" AutoGenerateColumns="False" DataKeyNames="OPLEIDING_ID, OPLEIDING_OMSCHRIJVING, EIGENAAR">
<Columns>
<asp:Boundfield DataField="OPLEIDING_OMSCHRIJVING"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_COLO_CODE"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_COHORT"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_CODE"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_VERSIE"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_LEERWEG"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_NIVEAU"></asp:BoundField>
<asp:Boundfield DataField="OPLEIDING_VERWIJDERD"></asp:BoundField>
<asp:templatefield>
<ItemTemplate>
<asp:Image ID="imgDelen" runat="server"/>
</ItemTemplate>
</asp:templatefield>
</Columns>
</asp:GridView>
Javascript功能:
function Test()
{
alert("hi");
return false;
}
RowDataBound事件:
Protected Sub OpleidingView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles OpleidingView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onclick") = ClientScript.GetPostBackEventReference(Me.OpleidingView, "Select$" & e.Row.RowIndex)
e.Row.ID = "Disable" & e.Row.RowIndex.ToString
Dim img As Image = CType(e.Row.FindControl("imgdelen"), Image)
img.ImageUrl = "~/Images/DefaultTheme/delen_zwart.png"
img.Attributes.Add("onclick", "return Test();")
End If
End Sub