enable disable checkboxes in datagrid

Posted on 2007-07-24
Last Modified: 2008-01-09
I have a datagrid that has checkbox and dropdown templates, I want to have a javascript function would grab a checkbox id  whichever checkbox in datagrid gets checked. So, function will loop thru datagrid rows and find the checked ones. How can I do that? Once it find that I want to be able to disable some of the rows checkboxes. That gets me confused how to do that?
Question by:jaws1021
    LVL 53

    Expert Comment

    An article that can help you on your way:
    Using CheckBoxes within the DataGrid control to select records
    LVL 53

    Accepted Solution

    You can handle the OnCheckedChanged event of the checkbox and disable the textbox in the event handler. Here are the steps in detail:

    1. In the .aspx file, add an OnCheckChanged attribute and bind it to the method you want to call. The template may look like this:

           <asp:CheckBox id="CheckBox1" OnCheckedChanged="Check_Clicked" runat="server" AutoPostBack="True">

    2. Create the "Check_Click" method in the code-behide file:

        public void Check_Clicked(object sender, System.EventArgs e)

    3. Most likely, you may need to retrieve the values in the row where the selected checkbox is located. However, the System.EventArgs does not contain any
    information about the current row, so we need to use the following method to achieve this (the following code is in the Check_Clicked method):

                   CheckBox cb=(CheckBox)sender;
            DataGridItem dgi=(DataGridItem)cb.NamingContainer;
            HyperLink hl=(HyperLink)dgi.Cells[0].Controls[1];     //revise the code to retrieve the control you want
                     ...  //Do other tasks you want, such as disabling a given textbox


    Author Comment

    I am sorry I should have written I need this on client side, so without using ajax I don't want to my page to refresh. I actually did whole project at the server side and on checkchanged event everything was working perfect except page refresh then I tried to put ajax, ajax stopped refreshing whole page but didn't stop flickering dropdown , which I found out later that was bug for IE browser 6, which is okay for the other ones such as firefox or even maybe for IE7, so now I am tried of wasting my time and I wan to to do old fashion javascript so it will be no refreshing ... I need this above code to be doing same thing on javascript, I am not that good at javascript  but I will manage. Thanks.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now