473,666 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6558
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:TemplateCo lumn HeaderText="Boo lean Value">
<ItemTemplate >
<asp:CheckBox id=match runat="server" onCheckedChange d="updateStatus "
Checked='<%# DataBinder.Eval (Container, "DataItem.Boole an") %>'
AutoPostBack="T rue">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Boo lean Value">
<ItemTemplate >
<asp:CheckBox id="Checkbox1" runat="server"
onCheckedChange d="updateStatus " Checked='<%# IIF(DataBinder. Eval(Container,
"DataItem.Boole an"),"true","fa lse") %>' AutoPostBack="T rue">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Boo lean Value">
<ItemTemplate >
<asp:Label id="Label1" runat="server"> <%#
IIF(DataBinder. Eval(Container, "DataItem.Boole an"),"Yes","No" )
%></asp:Label>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

Ken
MVP [ASP.NET]
"Asha" <As**@discussio ns.microsoft.co m> wrote in message
news:7F******** *************** ***********@mic rosoft.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.
<ItempTemplat e>
<asp:Checkbox RunAt=Server Id="chkActive" Checked='<%# DataBinder.Eval
(Container.Data Item, "<col_name> ") %>' />
</ItempTemplate>
Here, checkbox is checked based on the <col_name> column

Option 2 - Use an utility function.
<ItempTemplat e>
<asp:Checkbox RunAt=Server Id="chkActive" Checked='<%#
IsActive(DataBi nder.Eval (Container.Data Item, "<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**@discussio ns.microsoft.co m> wrote in message
news:7F******** *************** ***********@mic rosoft.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
16177
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 like '876543', when the user clicks on the check box, otherwise the fields should be blank, the value of the select box dosnt matter much, only that it defaults to USA, when the user checks it. Can anyone help? i have tried a google with no luck,...
2
1716
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 how to determine the checkboxes and save data into
0
2156
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 these selected fields and allow user to click one or more CheckBox controls to activate this bit on the database table for a required ID. I have already added a template column to the DataGrid and I can get the
1
1995
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 will check the checkbox(if it is approved) and then there is a confirmation button on the page. After them make the changes, they will hit the confirmation button so that the database will be updated accordingly. I am not using dataset at this...
2
5446
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 values in the underlying datatable column, and resets the binding to the datagrid. The only problem is that, when the user pages back and forth in the datagrid, their selection is overwritten with the default selection in page load. So, if the...
6
2610
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 to set/unset the checkbox. I tried the following in the ItemTemplate... <asp:CheckBox ID="chkShowNpVar" Text="" Checked='<%(DataBinder.Eval(Container.DataItem, "showVar")=="y" ? true :
2
3042
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 post but doesn't seem to haven't any affect. It doesn't appear to call the UpdateMailSubscribers method.
0
1098
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" runat="server" DataKeyField="serial" AutoGenerateColumns="True"> <ItemStyle></ItemStyle> <HeaderStyle></HeaderStyle> <Columns>
3
3145
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 expects a DataGridColumn so I instantiated an object of type TemplateColumn that I had hoped I could add a CheckBox to. I soon discovered that the ItemTemplate property of the TemplateColumn class returned an object that had implemented the...
0
8444
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
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
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
8781
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
8551
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
6198
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
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.