Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Setting asp:checkbox "checked" property in datagrid


Message #1 by mpiehota@r... on Tue, 22 Jan 2002 01:46:04
I'm using a datagrid to display records from a database.  Based on the 

value of a specific field, I want to set the "checked" property of a 

asp:checkbox control accordingly.  For example, if the value 

equals "YES", the checkbox is checked; if the value equals "NO", then the 

check box is not checked.  Any suggestions?
Message #2 by "Jeremy Hofmann" <jlhofmann@h...> on Wed, 23 Jan 2002 23:35:32
Depending on you datasource, use a test for equivalence:



Example for Boolean 0,1 Values:



<ASP:CHECKBOX AutoPostBack="True" Runat="Server" Checked=<%# ((int)

DataBinder.Eval(Container.DataItem,"YourBooleanField")==1) %> />



Example for "YES" / "NO" Strings:



<ASP:CHECKBOX AutoPostBack="True" Runat="Server" Checked=<%# 

(DataBinder.Eval(Container.DataItem,"YourYesNoField")=="YES") %> />



Remember that the Checked attribute expects a boolean value. I recommend 

using 0,1 values as they result in better performance.



> I'm using a datagrid to display records from a database.  Based on the 

> value of a specific field, I want to set the "checked" property of a 

> asp:checkbox control accordingly.  For example, if the value 

> equals "YES", the checkbox is checked; if the value equals "NO", then 

the 

> check box is not checked.  Any suggestions?
Message #3 by mpiehota@r... on Thu, 24 Jan 2002 03:18:30
When I use the convention you've suggested, the following HTML code is 

generated:



<input type="checkbox" checked=True  value="49">

<input type="checkbox" checked=False  value="50">



However, when the page is viewed in IE6, both checkboxes are selected 

(i.e., checked ). Did I miss something?
Message #4 by LUCAS Philippe <Philippe.Lucas@p...> on Thu, 24 Jan 2002 07:52:28 +0100
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C1A4A3.B04E98D0

Content-Type: text/plain;

	charset="iso-8859-1"



I think that you must write :



	<input type="checkbox" checked  value="49">

	<input type="checkbox" value="50">



And that's right



Philippe Lucas



-----Original Message-----

From: mpiehota@r... [mailto:mpiehota@r...]

Sent: jeudi 24 janvier 2002 4:19

To: ASP+

Subject: [aspx] Re: Setting asp:checkbox "checked" property in datagrid





When I use the convention you've suggested, the following HTML code is 

generated:



<input type="checkbox" checked=True  value="49">

<input type="checkbox" checked=False  value="50">



However, when the page is viewed in IE6, both checkboxes are selected 

(i.e., checked ). Did I miss something?








  Return to Index