473,396 Members | 1,812 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.

Datagrid and Databinding

I've got two tables that are linked by a field. The first table
contains a list of items (like a checklist). The second table contains
the corresponding a record for each user and each checklist item. The
records in the second table don't exist initally, only after the user
fills in the checklist and submits from a form.

I'm trying to get a datagrid to show two columns. One being all of the
checklist items and the second being a checkbox. All checkboxes will
be unchecked at first since there is no corresponding record yet. The
user will check off completed items from the checklist and submit.
Then a record for each checklist item will be written to the second
table.

My problem is since there is no record, the value of the checkbox is
NULL initially and the checkbox field can't be null. Anyone know of a
way around this?

Thanks!

Jul 21 '05 #1
2 2255
I hope I'm understanding your problem correctly. One way to set your
DataTable to have an initial value instead of a null value is to set the
DefaultValue, AllowDBNull, and DataType properties:

DataTable table = new DataTable();
table.Columns.Add(
new DataColumn());
table.Columns[0].DataType = typeof (System.Boolean);
table.Columns[0].DefaultValue = false;
table.Columns[0].AllowDBNull = false;

This way it will load with the user's default anwers.

Cheers,
Steve

"sdeezdaone" wrote:
I've got two tables that are linked by a field. The first table
contains a list of items (like a checklist). The second table contains
the corresponding a record for each user and each checklist item. The
records in the second table don't exist initally, only after the user
fills in the checklist and submits from a form.

I'm trying to get a datagrid to show two columns. One being all of the
checklist items and the second being a checkbox. All checkboxes will
be unchecked at first since there is no corresponding record yet. The
user will check off completed items from the checklist and submit.
Then a record for each checklist item will be written to the second
table.

My problem is since there is no record, the value of the checkbox is
NULL initially and the checkbox field can't be null. Anyone know of a
way around this?

Thanks!

Jul 21 '05 #2
Steve,
Thanks for the response. I'm changing my approach as I was
unsuccessful with the datagrid. Here is my code below. My problem is
when there is no record in the second table that matches a record in
the first table. The first table is a list of checklist items. New
ones can be added. When added, I need an unchecked checkbox to display
for this item. Since there is no matching record, I get an error:
"There is no row at position ?" How can I have the code ignore the
fact that there is no matching record and by default make it an
unchecked checkbox?

Thanks!

dschecklist = GetEOMCheckList()
dschecklistdata = GetEOMCheckListData(m_site_id, txtMonth, txtYear)

For x = 0 To dschecklist.Tables(0).Rows.Count - 1

trRow = New HtmlTableRow
trRow.Attributes.Add("class", "Survey_Label")

tdData = New HtmlTableCell
lblcelldata = New Label
lblcelldata.Text = " " &
dschecklist.Tables(0).Rows(x).Item("eom_descriptio n")
tdData.Controls.Add(lblcelldata)
trRow.Controls.Add(tdData)

tdData = New HtmlTableCell
lblcelldata = New Label
lblcelldata.Text = " " &
dschecklist.Tables(0).Rows(x).Item("eom_detail")
tdData.Controls.Add(lblcelldata)
trRow.Controls.Add(tdData)

tdData = New HtmlTableCell
tdData.Align = "center"
ckcelldata = New CheckBox
ckcelldata.ID = "eomcomplete_" &
dschecklistdata.Tables(0).Rows(x).Item("eom_checkl ist_data_id")
If
dschecklistdata.Tables(0).Rows(x).Item("eom_comple te") = True Then
ckcelldata.Checked = True
End If
tdData.Controls.Add(ckcelldata)
trRow.Controls.Add(tdData)

tblData.Controls.Add(trRow)

Next
Steve Goodyear wrote:
I hope I'm understanding your problem correctly. One way to set your
DataTable to have an initial value instead of a null value is to set the DefaultValue, AllowDBNull, and DataType properties:

DataTable table = new DataTable();
table.Columns.Add(
new DataColumn());
table.Columns[0].DataType = typeof (System.Boolean);
table.Columns[0].DefaultValue = false;
table.Columns[0].AllowDBNull = false;

This way it will load with the user's default anwers.

Cheers,
Steve

"sdeezdaone" wrote:
I've got two tables that are linked by a field. The first table
contains a list of items (like a checklist). The second table contains the corresponding a record for each user and each checklist item. The records in the second table don't exist initally, only after the user fills in the checklist and submits from a form.

I'm trying to get a datagrid to show two columns. One being all of the checklist items and the second being a checkbox. All checkboxes will be unchecked at first since there is no corresponding record yet. The user will check off completed items from the checklist and submit.
Then a record for each checklist item will be written to the second
table.

My problem is since there is no record, the value of the checkbox is NULL initially and the checkbox field can't be null. Anyone know of a way around this?

Thanks!


Jul 21 '05 #3

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

Similar topics

4
by: Angel | last post by:
How can I update the datatable with the datagrid values after the datagrid itself has been modified.? I assume it's not automatically done. Thanks.
2
by: Scott | last post by:
Hi all. A few days ago i ask this question and got a good quick response. I tried out what they said and it worked. However I have now come to try the same thing in another program and it...
0
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...
2
by: wolfgang wagner | last post by:
hi all! im trying to edit data in a datagrid (like described here: http://aspnet.4guysfromrolla.com/articles/071002-1.aspx) but if i click the edit button i get the following error invalid...
8
by: Jeff | last post by:
Hi - I'm having trouble Databinding a SQLDataReader to a DataGrid control. I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in a directory of...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
0
by: mcollier | last post by:
I'm trying to develop a page template for the ASP.NET 1.1 project I'm working on. I want to have something like Master Pages (from ASP.NET 2.0). I'm having a problem now with databinding on a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.