Datagrid and Databinding

S

sdeezdaone

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!
 
G

Guest

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
 
S

sdeezdaone

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_description")
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_checklist_data_id")
If
dschecklistdata.Tables(0).Rows(x).Item("eom_complete") = True Then
ckcelldata.Checked = True
End If
tdData.Controls.Add(ckcelldata)
trRow.Controls.Add(tdData)

tblData.Controls.Add(trRow)

Next


Steve said:
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 said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top