473,231 Members | 1,540 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,231 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 2248
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.