473,626 Members | 3,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CheckBox in a DataGrid

Hello,
I'm creating a table on the fly that is used by a datagrid. I'm also
creating a tableStyle that is used for the datagrid to make it look like I
want.
I'm using the DataGridBoolCol umn to make one column a CheckBox field. It
shows up fine...as a CheckBox. I looped through the table and stored a true
or false in the checkbox column but it appears to have no effect on the
checkbox column. No matter what I store there (true/false), when I run the
app all the checkboxes are checked/greyed. I thought I could store a true or
false in this column of the table and it would either be checked or
unchecked in the CheckBox...but that doesn't seem to work. Am I going about
it wrong?
Any help would be appreciated...
Thanks
Nov 15 '05 #1
3 4853
Public Class DynamicItemTemp late

' ITemplate - When implemented by a class, defines the Control object

' to which child controls and templates belong. These child controls

' are in turn defined within an inline template.

Implements ITemplate

Public Overridable Overloads Sub InstantiateIn(B yVal container As Control)
Implements ITemplate.Insta ntiateIn

' InstantiateIn - When implemented by a class, defines the Control

' object to which child controls and templates belong. These child

' controls are, in turn, defined within an inline template.

'

' Create an instance of a CheckBox object.

Dim oCheckBox As CheckBox = New CheckBox

' When the DataBinding event of the CheckBox fires, call the sub

' BindCheckBox to properly bind.

AddHandler oCheckBox.DataB inding, AddressOf BindCheckBox

'Add the CheckBox to the controls collection.

oCheckBox.Enabl ed = False

container.Contr ols.Add(oCheckB ox)

End Sub

Public Sub BindCheckBox(By Val sender As Object, ByVal e As EventArgs)

'Create a new instance of a CheckBox.

Dim oCheckBox As CheckBox = CType(sender, CheckBox)

Dim container As DataGridItem = CType(oCheckBox .NamingContaine r,
DataGridItem)

'Evaluate the data from the Grid item and set the Checked property

' appropriatly

If container.DataI tem("fCurrent") .GetType.ToStri ng = "System.DBN ull" Then

oCheckBox.Check ed = False

Else

oCheckBox.Check ed = CBool(container .DataItem("fCur rent"))

End If

End Sub

"Randy" <te**@temp.co m> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
I'm creating a table on the fly that is used by a datagrid. I'm also
creating a tableStyle that is used for the datagrid to make it look like I
want.
I'm using the DataGridBoolCol umn to make one column a CheckBox field. It
shows up fine...as a CheckBox. I looped through the table and stored a true or false in the checkbox column but it appears to have no effect on the
checkbox column. No matter what I store there (true/false), when I run the
app all the checkboxes are checked/greyed. I thought I could store a true or false in this column of the table and it would either be checked or
unchecked in the CheckBox...but that doesn't seem to work. Am I going about it wrong?
Any help would be appreciated...
Thanks

Nov 15 '05 #2
Thanks for the info idog...but I'm still kind of in the dark on this. I
can't really tell what you're doing here in this code...

"idog" <id****@hotmail .com> wrote in message
news:uT******** *****@tk2msftng p13.phx.gbl...
Public Class DynamicItemTemp late

' ITemplate - When implemented by a class, defines the Control object

' to which child controls and templates belong. These child controls

' are in turn defined within an inline template.

Implements ITemplate

Public Overridable Overloads Sub InstantiateIn(B yVal container As Control)
Implements ITemplate.Insta ntiateIn

' InstantiateIn - When implemented by a class, defines the Control

' object to which child controls and templates belong. These child

' controls are, in turn, defined within an inline template.

'

' Create an instance of a CheckBox object.

Dim oCheckBox As CheckBox = New CheckBox

' When the DataBinding event of the CheckBox fires, call the sub

' BindCheckBox to properly bind.

AddHandler oCheckBox.DataB inding, AddressOf BindCheckBox

'Add the CheckBox to the controls collection.

oCheckBox.Enabl ed = False

container.Contr ols.Add(oCheckB ox)

End Sub

Public Sub BindCheckBox(By Val sender As Object, ByVal e As EventArgs)

'Create a new instance of a CheckBox.

Dim oCheckBox As CheckBox = CType(sender, CheckBox)

Dim container As DataGridItem = CType(oCheckBox .NamingContaine r,
DataGridItem)

'Evaluate the data from the Grid item and set the Checked property

' appropriatly

If container.DataI tem("fCurrent") .GetType.ToStri ng = "System.DBN ull" Then

oCheckBox.Check ed = False

Else

oCheckBox.Check ed = CBool(container .DataItem("fCur rent"))

End If

End Sub

"Randy" <te**@temp.co m> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
I'm creating a table on the fly that is used by a datagrid. I'm also
creating a tableStyle that is used for the datagrid to make it look like I want.
I'm using the DataGridBoolCol umn to make one column a CheckBox field. It
shows up fine...as a CheckBox. I looped through the table and stored a true
or false in the checkbox column but it appears to have no effect on the
checkbox column. No matter what I store there (true/false), when I run the app all the checkboxes are checked/greyed. I thought I could store a

true or
false in this column of the table and it would either be checked or
unchecked in the CheckBox...but that doesn't seem to work. Am I going

about
it wrong?
Any help would be appreciated...
Thanks


Nov 15 '05 #3
Check this example. I'm assuming that you want a C# solution, given that
this is the C# newsgroup.

http://www.codeproject.com/aspnet/datagridcheckbox.asp

Pete

"Randy" <te**@temp.co m> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
I'm creating a table on the fly that is used by a datagrid. I'm also
creating a tableStyle that is used for the datagrid to make it look like I
want.
I'm using the DataGridBoolCol umn to make one column a CheckBox field. It
shows up fine...as a CheckBox. I looped through the table and stored a true or false in the checkbox column but it appears to have no effect on the
checkbox column. No matter what I store there (true/false), when I run the
app all the checkboxes are checked/greyed. I thought I could store a true or false in this column of the table and it would either be checked or
unchecked in the CheckBox...but that doesn't seem to work. Am I going about it wrong?
Any help would be appreciated...
Thanks

Nov 15 '05 #4

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

Similar topics

0
2153
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
2
3122
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
2397
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly - also when using the edit-mode in the datagrid.
1
4146
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub dgRegGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgRegGrid.PageIndexChanged I then do a loop to check the checkbox state.
0
1854
by: mehul | last post by:
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip in ASP.NET Hi, I am trying to develop an ASP.NET application. I am using TabStrip (which is part of IE WebControls). Inside a tab I have a datagrid defined as follows:
7
2270
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the Datagrid that will fire off when the Checkbox is changed? regards /Lars
10
2423
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox control in a datagrid? Now I have a Select column but the problem is that the user needs to select more than one record and send them all to print, instead of being one by one like is now with the Select column. Another question, is it possible to...
2
3041
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.
9
1589
by: Rekha | last post by:
The data is filled in datagrid. I want to know how to add a checkbox column in datagrid? In the runtime, checkbox is checked then instead of checkbox value the (caseID )column value is retained. I know there is a lot of article on datagrid with checkbox but nothing helped me . Can anyone help me how to proceed ? Thanks
3
3142
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
8202
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
8641
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
8366
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,...
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
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
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2628
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
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
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.