473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

default value for checkbox in a datagrid.

greetings,
i'm loading a datagrid and my gird has checkbox, i want these checkboxex to
be check based on the value from the db? can someone please show me the code
for it? thanks
Nov 18 '05 #1
2 6534
Depending on your data, you might be able to use an IIF statement inline to
indicate whether the checkbox is checked:

<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:CheckBox id=match runat="server" onCheckedChanged="updateStatus"
Checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>'
AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:CheckBox id="Checkbox1" runat="server"
onCheckedChanged="updateStatus" Checked='<%# IIF(DataBinder.Eval(Container,
"DataItem.Boolean"),"true","false") %>' AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:Label id="Label1" runat="server"><%#
IIF(DataBinder.Eval(Container, "DataItem.Boolean"),"Yes","No")
%></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Ken
MVP [ASP.NET]
"Asha" <As**@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
greetings,
i'm loading a datagrid and my gird has checkbox, i want these checkboxex
to
be check based on the value from the db? can someone please show me the
code
for it? thanks


Nov 18 '05 #2
Option 1 - Used the Checked attribute of the checkbox.
<ItempTemplate>
<asp:Checkbox RunAt=Server Id="chkActive" Checked='<%# DataBinder.Eval
(Container.DataItem, "<col_name>") %>' />
</ItempTemplate>
Here, checkbox is checked based on the <col_name> column

Option 2 - Use an utility function.
<ItempTemplate>
<asp:Checkbox RunAt=Server Id="chkActive" Checked='<%#
IsActive(DataBinder.Eval (Container.DataItem, "<col_name>")) %>' />
</ItempTemplate>
IsActive is a protected method (can be any name) in the page returning True
or False based on the parameter passed.

Well, the 3rd option is to use ItemDateBound event of the grid.

HTH.

"Asha" <As**@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
greetings,
i'm loading a datagrid and my gird has checkbox, i want these checkboxex to
be check based on the value from the db? can someone please show me the code
for it? thanks

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sarah West | last post by:
Hi, I have the following problem; This is my form, i would like to default the select box to USA, and default the text field to a name such as 'Sarah' and the hidden field to another number...
2
by: Angie | last post by:
datagrid ex. a 1 checkbox b 2 checkbox c 3 checkbox once a user selects these 3 rows from a datagrid and i want to save the 1, 2, 3 value into the database how do i do this? I know...
0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
1
by: irene | last post by:
Hi, I am trying to update the checkbox value in a datagrid. I am using TemplateColumn to add the checkbox to the datagrid and it is showing correct data from the database now. Ideally, the end user...
2
by: Andre Ranieri | last post by:
Hi folks, I have a datagrid which contains a template item checkbox column. I've included a checkbox as a HeaderTemplate item which fires a server-side function to check or uncheck all the...
6
by: Alan Silver | last post by:
Hello, I am data binding a repeater that has a checkbox in the ItemTemplate. The data value coming out of the database is a char(1) field containing either "y" or "n". I want to use this value...
2
by: Adam Knight | last post by:
Hi all, I have a datagrid with a checkbox in one column. The checkbox is set to autopostback and calls a method named UpdateMailSubscribers. The first click on the checkbox cause the page to...
0
by: alan | last post by:
Hello, I have got a datagrid with first column as a checkbox. I'm trying to retrieve values from rows with checkbox checked. For one column I'm doing something like: <asp:datagrid id="Grid1"...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.