Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 15th, 2011, 01:48 PM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to make gridview checkbox act like radiobutton

Hi Imar,

My question is how to make checkboxes act like radiobuttons. My scenario is such that I have a GridView with a few columns where two of the columns are checkboxes. How can I make those checkboxes act like radiobuttons? I mean, if lets say checkbox1 of row 1 is checked, then if I check checkbox2 of row 1, then I'd want checkbox1 of that same row to be unchecked. I want to be able to achieve this type of validation on the client side (using javascript) though.

Thanks for the help.

Ed
Reply With Quote
  #2 (permalink)  
Old July 15th, 2011, 04:02 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Hi Ed,

You're probably better off asking future questions like this in a JavaScript or jQuery forum here at p2p.wrox.com as it's a bit beyond the scope of the book, and of what I can typically support on a forum like this.

Anyway, I quickly cooked up an example as I was a bit intrigued in the solution myself.

Edit: See attachment. This forum was eating my code (due to the call to the jQuery library on the Google web site) so I moved it to an attachment.

This jQuery code first assigns some code to the click event of each checkbox. It then wraps "this" (the checkbox) in a jQuery matched set and then use parent().parent() to traverse up from the checkbox through the table cell (td) to the table row (tr).

On the row, it finds all checkboxes and disables them using attr which enables you to set an attribute value on an element. At the item, the clicked checkbox is selected.

This code only fires if the checkbox has just been turned on. Otherwise (e.g. without the if check) you wouldn't be able to unckeck both items anymore (which may be what you want though).

This code assumes the same table structure as in my sample HTML so you may need to modify it a bit to match your HTML.

Cheers,

Imar
Attached Files
File Type: txt CheckoxesThatActLikeRadios.txt (1.4 KB, 32 views)
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; July 15th, 2011 at 04:09 PM.
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Edkch (July 15th, 2011)
  #3 (permalink)  
Old July 15th, 2011, 07:13 PM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to make gridview checkbox act like radiobutton

Hi Imar,

Thanks for the reply. I'll try to play with what you had and see if I can make it work with what I have. If not, I'll try to find the right forum to post this question with more details. Thanks again!!

Ed
Reply With Quote
  #4 (permalink)  
Old July 21st, 2011, 01:18 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Hi Ed,

I wrote a quick blog about this solution with a slightly better implementation: the code now uses closest() to find the nearest table row, rather than explicitly using the parent method: http://imar.spaanjaars.com/562/creat...ns-with-jquery

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
RadioButton with GridView Manoj Bisht ASP.NET 3.5 Professionals 1 March 18th, 2009 12:13 PM
Checkbox in Gridview yukijocelyn ASP.NET 2.0 Basics 0 September 24th, 2007 12:32 AM
Checkbox in GridView aliirfan84 ASP.NET 2.0 Professional 1 May 15th, 2007 03:59 PM
Dynamic checkbox and radiobutton lists Ric_H C# 1 April 5th, 2006 05:04 AM
Dynamic checkbox and radiobutton lists Ric_H General .NET 2 March 30th, 2006 12:52 PM



All times are GMT -4. The time now is 11:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.