juststeve
asked on
Initialize Checkboxes based on multi-DataTable conditions
This question picks up on an earlier question at: https://www.experts-exchange.com/questions/21781470/Generate-table-from-3-resultsets.html
I've refined my problem down to a fairly narrow focus. I'm able to accomplish all the dynamic Table/Column/Row generation and only need to solve the issue of correctly initializing the 'checked' or 'not check' property of the table's checkboxes.
Here's a sample of the sort of table i'll need to end up with:
Module1 Module2 Module3 Modulex
TitleA . . | .
TitleB . | | .
TitleC . . . .
. = unchecked boxes
| = checked boxes
As each cell is constructed it establishes titleID (CurrentRow) & moduleID (CurrentColumn). If the FKey table has a record that matches both titleID and moduleID then the checkBox control should initialize to 'checked'.
I've tried a few approaches but I can't figure out how to implement that stratagy.
Dim ds As New DataSet
Dim GetTitles = "select distinct strTitle, idTitle from FacilityTitles where FacilityID = 1 order by strTitle;"
GetTitles = GetTitles & "select ModuleName, moduleID from modules where moduleID > 0 order by ModuleID; "
GetTitles = GetTitles & "select moduleID, idTitle, ReqModID from RequiredModules where dateDue = '" & lbGetDateDue.SelectedValue & "' order by Moduleid "
ds = SqlHelper.ExecuteDataset(c onnStr, CommandType.Text, GetTitles)
ds.Tables(0).TableName = "Titles"
ds.Tables(1).TableName = "Modules"
ds.Tables(2).TableName = "FKey"
'build table
Dim tb As New HtmlTable
tb.CellSpacing = 1
tb.Border = 1
Dim tbr As New HtmlTableRow
Dim tbc As New HtmlTableCell
tbr.Cells.Add(tbc) ' empty cell in the corner
'build first row as Class 1 - X
For Each myModule As DataRow In ds.Tables("Modules").Rows
tbc = New HtmlTableCell
Dim lbl As New Label
lbl.Text = myModule(0)
tbc.Controls.Add(lbl)
tbr.Cells.Add(tbc)
Next
tb.Rows.Add(tbr) ' Add the row to table
Dim intRow As Integer = 0
For Each myTitle As DataRow In ds.Tables("Titles").Rows
'Dim myCurModuleID = ds.Tables("Modules").Rows
Dim myCurTitleID = myTitle(1)
tbr = New HtmlTableRow
tbc = New HtmlTableCell
Dim lbl As New Label
lbl.Text = myTitle(0)
tbc.Controls.Add(lbl)
tbr.Cells.Add(tbc) ' Add Title A - Z to first cell of each row
Dim i As Integer
For i = 0 To ds.Tables("Modules").Rows. Count - 1
' each iteration adds row
' with an unchecked checkbox
tbc = New HtmlTableCell
Dim cb = New CheckBox
'iterate thru all records in FKeys table
'to identify which rows have a idTitle field
'that matches the current idTitle (myTitle(1))
tbc.Controls.Add(cb)
tbr.Cells.Add(tbc)
Next
myConnection.Close()
tb.Rows.Add(tbr) ' add this row to table
intRow += 1
'initialize checkboxes to correct state
'generate resultset per row
Next
Me.Panel1.Controls.Add(tb)
I've refined my problem down to a fairly narrow focus. I'm able to accomplish all the dynamic Table/Column/Row generation and only need to solve the issue of correctly initializing the 'checked' or 'not check' property of the table's checkboxes.
Here's a sample of the sort of table i'll need to end up with:
Module1 Module2 Module3 Modulex
TitleA . . | .
TitleB . | | .
TitleC . . . .
. = unchecked boxes
| = checked boxes
As each cell is constructed it establishes titleID (CurrentRow) & moduleID (CurrentColumn). If the FKey table has a record that matches both titleID and moduleID then the checkBox control should initialize to 'checked'.
I've tried a few approaches but I can't figure out how to implement that stratagy.
Dim ds As New DataSet
Dim GetTitles = "select distinct strTitle, idTitle from FacilityTitles where FacilityID = 1 order by strTitle;"
GetTitles = GetTitles & "select ModuleName, moduleID from modules where moduleID > 0 order by ModuleID; "
GetTitles = GetTitles & "select moduleID, idTitle, ReqModID from RequiredModules where dateDue = '" & lbGetDateDue.SelectedValue
ds = SqlHelper.ExecuteDataset(c
ds.Tables(0).TableName = "Titles"
ds.Tables(1).TableName = "Modules"
ds.Tables(2).TableName = "FKey"
'build table
Dim tb As New HtmlTable
tb.CellSpacing = 1
tb.Border = 1
Dim tbr As New HtmlTableRow
Dim tbc As New HtmlTableCell
tbr.Cells.Add(tbc) ' empty cell in the corner
'build first row as Class 1 - X
For Each myModule As DataRow In ds.Tables("Modules").Rows
tbc = New HtmlTableCell
Dim lbl As New Label
lbl.Text = myModule(0)
tbc.Controls.Add(lbl)
tbr.Cells.Add(tbc)
Next
tb.Rows.Add(tbr) ' Add the row to table
Dim intRow As Integer = 0
For Each myTitle As DataRow In ds.Tables("Titles").Rows
'Dim myCurModuleID = ds.Tables("Modules").Rows
Dim myCurTitleID = myTitle(1)
tbr = New HtmlTableRow
tbc = New HtmlTableCell
Dim lbl As New Label
lbl.Text = myTitle(0)
tbc.Controls.Add(lbl)
tbr.Cells.Add(tbc) ' Add Title A - Z to first cell of each row
Dim i As Integer
For i = 0 To ds.Tables("Modules").Rows.
' each iteration adds row
' with an unchecked checkbox
tbc = New HtmlTableCell
Dim cb = New CheckBox
'iterate thru all records in FKeys table
'to identify which rows have a idTitle field
'that matches the current idTitle (myTitle(1))
tbc.Controls.Add(cb)
tbr.Cells.Add(tbc)
Next
myConnection.Close()
tb.Rows.Add(tbr) ' add this row to table
intRow += 1
'initialize checkboxes to correct state
'generate resultset per row
Next
Me.Panel1.Controls.Add(tb)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Post a link to it here as well.
So you don't want it to persist state? Could you just disable the checkboxes?
So you don't want it to persist state? Could you just disable the checkboxes?
ASKER