By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,221 Members | 1,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,221 IT Pros & Developers. It's quick & easy.

Datagrid and Databinding

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.