473,769 Members | 5,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read only checkbox, radio button (in ASP.NET GridView) solution

1 New Member
This is a solution to the problem. Works with .NET 2.0.

So the problem is displaying a data bound read-only checkbox or radio button in a GridView without actually disabling those controls.

I assume you know what templates are in a GridView. Examples are in VB.NET. Sorry...

So as a first step create a function in the page's underlying class that returns the string "checked" based on the bound data. Here's what I did. The underlying data table is storing bool values in bit fields.

Expand|Select|Wrap|Line Numbers
  1. Protected Function TrueToChecked(ByVal str As String) As String
  2.   Dim retval As String = ""
  3.   If "True" = str Then retval = "checked"
  4.   Return retval
  5. End Function
  6.  
Then create an ItemTemplate that uses regular HTML <input...> type radio button/checkbox controls. You have to embed a call to the above function in the tag. The parameter for the function will be the output of the Eval() function. It goes something like this:

[HTML]
<ItemTemplate >
exclude<input type="radio" <%# TrueToChecked(E val("force_excl ude")) %> onclick="window .focus();return false;"/>
<input type="radio" <%# TrueToChecked(E val("force_incl ude")) %> onclick="window .focus();return false;"/>include
</ItemTemplate>
[/HTML]

The TrueToChecked() function will be called with the string representation of the underlying data, every time the DataBind method of the ItemTemplate is called.

The control will be readonly thanks to the small JavaScript code hooked up to the 'onclick' event of the control.

Note, that the controls do not have the 'name' attribute defined. If you give a name, the radiobuttons will be treated as one group, and clicking on one, will uncheck all the others even though the JavaScript will prevent updating any of them. If for some reason you need to give names, add another function to the class that returns a unique name on every call. You can call this function to return a string as name the same way the TrueToChecked() function is called in the example. For checkboxes it does not matter.
Mar 29 '07 #1
0 2759

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4133
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
2
3493
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
2
3494
by: Advo | last post by:
Basically, ive got information in a table for the layout purposes, as its text for a questionnaire What i Need, is for instance when the user click a radio button, that information can be hidden. I tried <div id="myarea" style="visibility:hidden"><STRONG><font color="#4475AA"Question 2:</font></STRONG></divetc
3
5847
by: Harry Haller | last post by:
I have a radio button group. When the page loads none of them are selected. OnClick selects ONE and clicking another one selects a different one - this is normal behavior. I want to modify it so that clicking on a radio which is already selected will deselect it so that none of the group are selected. I can get the required behavior with a double-click: ondblclick="this.checked=!(this.checked);"
6
5738
by: Rob | last post by:
Hi all, I would like to have a textarea control on my web page that is complete with terms and conditions, in addition, I would like a radio button beneath this to indicate the acceptance of these terms and conditions. The part which I am struggling to find information online about is how to only activate the radio button (ie, prior to this event its disabled) when the user has scrolled to the bottom of the textarea.
3
2499
w33nie
by: w33nie | last post by:
I want to disable the text boxes, captain_name and captain_email, but only if the radio button, captain_guarantee, has NOT been checked. how do i do this? <form name="formTeamApplication" action="teams_process.php" method="post" onSubmit="validate()"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width='75'><span class='Body'>Team Name:</span></td> <td width='150'><input width="150"...
6
4825
by: Ang | last post by:
Is it possible to get the checkbox and radio button values from excel by c#? Thanks. *** Sent via Developersdex http://www.developersdex.com ***
2
2812
by: runway27 | last post by:
i am using a self submitting form <form action="<?php echo $_SERVER; ?>" method="POST" id="test2" name="test1"> i need to do a validation of textfields, checkboxes, radio buttons i am able to read, display and validate textfields after the form has been submitted however i am getting an error for checkbox and radio buttons.
3
2790
by: camdev | last post by:
I have a form with 2 radio buttons and multiple checkboxes (see example below). The one radio button indicates all and the other radio button indicates the user has chosen specific options (checkboxes) from a list. Can I use javascript to automatically select the 2nd radio button if the users clicks on any of the checkboxes? <form name=form1> <input type=radio name=Radio1 value=All> <input type=radio name=Radio1 value=Specific> <input...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.