Solved

Can't Check Checkboxes in ASP.NET

Posted on 2006-10-27
3
170 Views
Last Modified: 2010-04-07
I'm using VS2005. I want to use a Gridview with a checkbox in each row. How can I allow the user to check the boxes in the rows without having to go into edit mode for each row. I guess I'm looking for multi-row editing. Is that capable in ASP.NET/VS2005
0
Comment
Question by:wrwiii12
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 125 total points
ID: 17834554
The real problem is that the datagrid is a databound control. Without putting the row into edit mode it would not know how to persist the data back to the database. One trick I've used is to use an HTML checkbox (not as asp one) and bind the data to it declarativley in the normal way. This way the checkbox is editable and it's value is correct when first loaded. You can then check it in the usual way the only problem is saving this information in the database and for that I use a small bit of Atlas.

Here's my declarative data binding...
    <input type="CheckBox" onclick="javascript:UpdateStepStatus('<%#Eval("ItemId")%>', this.checked)"/>

and here's the JS function...
    function UpdateStepStatus(itemId, status)
    {
        WebServices.UpdateStepStatus(itemId, status);
    }

You will need a web service method which is simply this code in a file named WebServices.asmx...
    <System.Web.Services.WebMethod()> _
    Public Function UpdateStepStatus(ByVal itemId As Integer, ByVal checked As Boolean) As String
        'Update the data base set checked=checked where itemId=itemId
    End Function

And a reference to this webservice on your page...
    <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
        <Services>
            <atlas:ServiceReference Path="WebServices.asmx" />
        </Services>
    </atlas:ScriptManager>

You will also have to visit atlas.asp.net to download the Microsoft atlas code. This might sould like a lot of bother but beleive me this is really worth it. Not only will you get the ability to check your checkboxes without entering edit mode but as a bonus you can do all this without postbacks!

I have done this on a task list editor and it really works just like a local app with instant update and no postbacks.

0
 
LVL 11

Expert Comment

by:ethoths
ID: 18067312
I think I should get the points for this one.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

830 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