0

I have one GridView "gvDetail" which has 30 columns(include both Template and BoundField).

In that columns, I have One CheckBox "chkSelect" in the Second Column. And One LinkButton "lnkQC" in the 22nd Column.

I want to Enable the LinkButton when I check the CheckBox in the GridView. And also I want to Disable the LinkButton when I uncheck the CheckBox.

How to achieve this using JavaScript or JQuery? Please I need all your suggestions...

thevan
  • 10,052
  • 53
  • 137
  • 202

2 Answers2

1

Your LinkButton renders to simple anchor. The code will looks like this. If you have some links inside the table you will need to specify some css class to this linkbutton and change selector in this js.

$(document).ready(function() {
    $('#grid-table-id input:checkbox').change(function() {
        var linkDisableHandler = function(e) { 
                                       e.preventDefault();
                                       return false; 
                                 };

        if ($(this).is(':checked')) {
            $(this).closest('tr')
                   .find('a')
                   .removeClass('disabled')
                   .unbind('click', linkDisableHandler);
        } 
        else {
            $(this).closest('tr')
                   .find('a') 
                   .addClass('disabled')
                   .bind('click', linkDisableHandler);;
        }
    });
});

Now, I just changing the css class for link, but to disable link you need to take a look on this post: jQuery disable a link

Community
  • 1
  • 1
Samich
  • 29,157
  • 6
  • 68
  • 77
  • I have not used JQuery. How to call this JQuery? – thevan Nov 17 '11 at 07:29
  • You don't need to call it, it subscribes to events. Just put it to the end of the document. – Samich Nov 17 '11 at 07:30
  • But as I mentioned this code doesn't disable links, you need to take a look on the referenced post. You will find couple methods how to do this. – Samich Nov 17 '11 at 07:32
0

Just need to add onDatabound event of Gridview and Register the javascript of Checkbox changed event and pass the linkbutton id as a parameter in Registered javascript. You will get the linkbutton in javascript, you can do as you want.

Rahul.R.Parmar
  • 74
  • 1
  • 11