[RESOLVED]jQuery binding function to Gridview Select


I have a gridview with Select LinkButton, static ID.

I try to add onclick method to the LinkButton (actually an a tag) with the following code:

$(function () {
            $("#LinkButton1").click(function (e) { doSomething(); });

Unfortunately the the onclick event is not added to the Linkbutton,

ant idea why ?


Ashim’s solution will resolve your click event not executing issue.How ever you may face one more issue here since you have made the clientid mode static the javascript function will work only for the first button.
To Resolve it you need to remove the clientID mode property from linkbutton and use the Jquery’s class selector to access the control from gridview in jquery code

Sample Code
Assign a css class to your link button like given below

<asp:TemplateField HeaderText="Department_Name">
                    <asp:LinkButton ID="LinkButton1" runat="server" class="lnkbutton">LinkButton</asp:LinkButton>


<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

        $(document).ready(function () {
            //Attach click event handler to your linkbutton using the css selector
            $(".lnkbutton").click(function () {

        function doSomething() {

and then use the below code

Leave a Reply