Solved

Can't Check Checkboxes in ASP.NET

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Resizing code128 barcode using cold fusion 14 164
create a website 10 76
How does Amazon build their pages? 3 71
Build and evolve an interactive experience 1 96
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 manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
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. …

785 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