Solved

Can't Check Checkboxes in ASP.NET

Posted on 2006-10-27
3
159 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
Comment Utility
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
Comment Utility
I think I should get the points for this one.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now