Solved

Can't Check Checkboxes in ASP.NET

Posted on 2006-10-27
3
162 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
COldFusion html Display 10 107
Resizing code128 barcode using cold fusion 14 154
Eclipse for PHP 1 95
How does Amazon build their pages? 3 66
In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

920 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

16 Experts available now in Live!

Get 1:1 Help Now