473,396 Members | 2,024 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,396 software developers and data experts.

Programmatically binding datagrid

Hi,

I have a datagrid that contains a checkbox template column. I have followed
the sample in Q306227, but I have a problem evaluating the content of the
datagrid columns to decide a value for the checkboxes check property.

According to the sample I should use this statement in the BindCheckbox
event to evaluate a column:

Public Sub BindCheckBox(ByVal 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.NamingContainer,
DataGridItem)
'Evaluate the data from the Grid item and set the Checked property
' appropriatly
If container.DataItem("contract").GetType.ToString = "System.DBNull"
Then
oCheckBox.Checked = False
Else
oCheckBox.Checked = CBool(container.DataItem("contract"))
End If

End Sub
The problem here is that my project is configured to use "Option Strict" and
does therefore not allow the statement

If container.DataItem("contract").GetType.ToString = "System.DBNull" Then

I tried to use Container.cells(2).text instead, but this only returns a
empty string in all rows.

Any suggestions on how to to do this ?

Regards

Niclas
Nov 18 '05 #1
2 2189
Hi, Niclas

Why not try
If IsDBNull(container.DataItem("contract")) The
oCheckBox.Checked = Fals
Els
oCheckBox.Checked = CBool(container.DataItem("contract")
End I

Bin Song, MC

----- Niclas Lindblom wrote: ----

Hi

I have a datagrid that contains a checkbox template column. I have followed
the sample in Q306227, but I have a problem evaluating the content of the
datagrid columns to decide a value for the checkboxes check property

According to the sample I should use this statement in the BindCheckbox
event to evaluate a column

Public Sub BindCheckBox(ByVal 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.NamingContainer,
DataGridItem
'Evaluate the data from the Grid item and set the Checked propert
' appropriatl
If container.DataItem("contract").GetType.ToString = "System.DBNull"
The
oCheckBox.Checked = Fals
Els
oCheckBox.Checked = CBool(container.DataItem("contract")
End I

End Su
The problem here is that my project is configured to use "Option Strict" and
does therefore not allow the statemen

If container.DataItem("contract").GetType.ToString = "System.DBNull" The

I tried to use Container.cells(2).text instead, but this only returns a
empty string in all rows

Any suggestions on how to to do this

Regard

Niclas

Nov 18 '05 #2
Hi, Niclas

Why not try
If IsDBNull(container.DataItem("contract")) The
oCheckBox.Checked = Fals
Els
oCheckBox.Checked = CBool(container.DataItem("contract")
End I

Bin Song, MC

----- Niclas Lindblom wrote: ----

Hi

I have a datagrid that contains a checkbox template column. I have followed
the sample in Q306227, but I have a problem evaluating the content of the
datagrid columns to decide a value for the checkboxes check property

According to the sample I should use this statement in the BindCheckbox
event to evaluate a column

Public Sub BindCheckBox(ByVal 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.NamingContainer,
DataGridItem
'Evaluate the data from the Grid item and set the Checked propert
' appropriatl
If container.DataItem("contract").GetType.ToString = "System.DBNull"
The
oCheckBox.Checked = Fals
Els
oCheckBox.Checked = CBool(container.DataItem("contract")
End I

End Su
The problem here is that my project is configured to use "Option Strict" and
does therefore not allow the statemen

If container.DataItem("contract").GetType.ToString = "System.DBNull" The

I tried to use Container.cells(2).text instead, but this only returns a
empty string in all rows

Any suggestions on how to to do this

Regard

Niclas

Nov 18 '05 #3

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

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
6
by: ad | last post by:
I use the code to create a DataGrid and filled with data, But the DataGrid1 didn't display in WebForm. How can I display the DataGrid after creating it? DataGrid DataGrid1 = new DataGrid();
1
by: Niclas Lindblom | last post by:
Hi, I have a datagrid that contains a checkbox template column. I have followed the sample in Q306227, but I have a problem evaluating the content of the datagrid columns to decide a value for...
18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
1
by: Craig | last post by:
How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change the databinding to another column at runtime. ...
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...
8
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some...
5
by: Brad Shook | last post by:
I am trying to bind one column of a datagrid to a seperate textbox and the rest of the fields to a datagrid. the comments are too large to fit in a datagrid so I created a textbox below the...
2
by: David C | last post by:
I followed the torial using this from MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vste chart/html/vbtchCreatingWebServerControlTemplatesProgrammatically.asp to...
6
by: Andrew Jocelyn | last post by:
Hi How do I programmatically change (read/write) the values in this app.config file at runtime? Specifically I want to change the client endpoint address but it would be nice to change other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.