Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't Check Checkboxes in ASP.NET

Posted on 2006-10-27
3
Medium Priority
?
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 500 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

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!
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
Suggested Courses

688 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