开发者

How to attach JavaScript on click event of GridView's EditButton/DeleteButton?

I have a GridView which has EditButton and DeleteButton enabled. When the user clicks either of the buttons, I want to execute a custom JavaScript codes. In an ordinary Button, we can accomplish this by setting 开发者_运维百科OnClientClick="MyJSFunction();".

Thanks!


here i consider this is your last column in Grid-view

<asp:CommandField ShowEditButton="true" ButtonType="Image" HeaderText="Edit" EditImageUrl="~/Images/edit.png" UpdateImageUrl="~/Images/update.png" CancelImageUrl="~/Images/cancel.jpg" >
</asp:CommandField>

and write following code in code-behind which will call your custom java-script function.

Protected Sub gvSectionTimePeriod_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSectionTimePeriod.RowDataBound

  Dim iIndex As Integer = //here write index of yr last column
  CType(e.Row.Cells(iIndex).Controls(0), ImageButton).Attributes.Add("onclick", "return ValidateData();")

End Sub

and here yr java-script part

<script language="javascript" type="text/javascript">
    function ValidateData()
    {
        //your code
    }
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜