M
mtsylvester
Hi All,
How do I add a List Box to a dynamic Details View. I want to replace
the check boxes with list boxes. If I try to simply replace the check
box with a list box it complains about not being able to convert it to
a datacontrol field. Below is a portion of my current code behind. By
the way I tried doing dynamic templates and was not able to get it to
work. Please help, this is driving me nuts.
Thanks
Dim DetailsViewAudit As New DetailsView()
Dim UpdateString As String = Nothing
Dim UpdateParam As String = Nothing
sSQL = "Select * from [Audit Formats] where [Audit Type]='" &
AuditType & "' order by [Rank]"
oCmd = New SqlCommand(sSQL, oCnn)
'start the update string
UpdateString = "UPDATE [" & TypeName & "] SET "
Dim drAuditFormat As SqlDataReader = oCmd.ExecuteReader()
Dim DetailsField As New BoundField()
Dim DetailsCheckBox As New CheckBoxField()
DetailsField.HeaderText = "UniqueKey"
DetailsField.DataField = "UniqueKey"
DetailsField.Visible = False
DetailsViewAudit.Fields.Add(DetailsField)
Do While (drAuditFormat.Read())
If drAuditFormat(4) <> "AssessmentNumber" Then 'skip
assessment number
UpdateParam = "[" & drAuditFormat(4) & "]=@" &
drAuditFormat(4) & ","
UpdateString = UpdateString & UpdateParam
End If
Select Case drAuditFormat(3)
Case 1 'text box field
DetailsField = New BoundField()
DetailsField.DataField = drAuditFormat(4)
DetailsField.HeaderText = drAuditFormat(5)
Select Case drAuditFormat(4)
Case "AssessmentNumber"
DetailsField.Visible = False
DetailsField.ReadOnly = True 'set
assessment number to read only
Case "CorrectiveAction"
DetailsField.ItemStyle.Wrap = True
DetailsField.ItemStyle.Height = 150
DetailsField.ItemStyle.Width = 150
DetailsField.ItemStyle.VerticalAlign =
VerticalAlign.Top
DetailsField.ControlStyle.CssClass =
"WrapText" 'not working yet
End Select
DetailsViewAudit.Fields.Add(DetailsField)
Case 2 'check box field
DetailsCheckBox = New CheckBoxField
DetailsCheckBox.DataField = drAuditFormat(4)
DetailsCheckBox.HeaderText = drAuditFormat(5)
DetailsCheckBox.Text = "Comply"
DetailsViewAudit.Fields.Add(DetailsCheckBox)
End Select
Loop
drAuditFormat.Close()
PlaceHolderDetails.Controls.Add(DetailsViewAudit)
Dim keyArray() As String = {"UniqueKey"}
DetailsViewAudit.DataKeyNames = keyArray
DetailsViewAudit.AutoGenerateEditButton = True
DetailsViewAudit.AutoGenerateRows = False
DetailsViewAudit.Fields(2).HeaderStyle.Width = 6000
DetailsViewAudit.Fields(2).ItemStyle.Width = 300
DetailsViewAudit.CellPadding = 0
DetailsViewAudit.CellSpacing = 1
SqlDataSourceDetail.ConnectionString =
("MyDataSource") SqlDataSourceDetail.SelectCommandType
= SqlDataSourceCommandType.Text
SqlDataSourceDetail.SelectCommand = "SELECT * FROM [" &
TypeName & "] where AssessmentNumber='" & AuditNumber & "'"
SqlDataSourceDetail.UpdateCommandType =
SqlDataSourceCommandType.Text
'finalize update string
UpdateString = Mid(UpdateString, 1, Len(UpdateString) - 1) & "
WHERE AssessmentNumber='" & AuditNumber & "'"
SqlDataSourceDetail.UpdateCommand = UpdateString
DetailsViewAudit.DataSourceID = "SqlDataSourceDetail"
'DetailsViewAudit.DataBind() 'not required
AddHandler DetailsViewAudit.ModeChanging, AddressOf
DetailsViewAudit_ModeChanging
AddHandler DetailsViewAudit.ItemUpdating, AddressOf
DetailsViewAudit_ItemUpdating
AddHandler DetailsViewAudit.ItemUpdated, AddressOf
DetailsViewAudit_ItemUpdated
How do I add a List Box to a dynamic Details View. I want to replace
the check boxes with list boxes. If I try to simply replace the check
box with a list box it complains about not being able to convert it to
a datacontrol field. Below is a portion of my current code behind. By
the way I tried doing dynamic templates and was not able to get it to
work. Please help, this is driving me nuts.
Thanks
Dim DetailsViewAudit As New DetailsView()
Dim UpdateString As String = Nothing
Dim UpdateParam As String = Nothing
sSQL = "Select * from [Audit Formats] where [Audit Type]='" &
AuditType & "' order by [Rank]"
oCmd = New SqlCommand(sSQL, oCnn)
'start the update string
UpdateString = "UPDATE [" & TypeName & "] SET "
Dim drAuditFormat As SqlDataReader = oCmd.ExecuteReader()
Dim DetailsField As New BoundField()
Dim DetailsCheckBox As New CheckBoxField()
DetailsField.HeaderText = "UniqueKey"
DetailsField.DataField = "UniqueKey"
DetailsField.Visible = False
DetailsViewAudit.Fields.Add(DetailsField)
Do While (drAuditFormat.Read())
If drAuditFormat(4) <> "AssessmentNumber" Then 'skip
assessment number
UpdateParam = "[" & drAuditFormat(4) & "]=@" &
drAuditFormat(4) & ","
UpdateString = UpdateString & UpdateParam
End If
Select Case drAuditFormat(3)
Case 1 'text box field
DetailsField = New BoundField()
DetailsField.DataField = drAuditFormat(4)
DetailsField.HeaderText = drAuditFormat(5)
Select Case drAuditFormat(4)
Case "AssessmentNumber"
DetailsField.Visible = False
DetailsField.ReadOnly = True 'set
assessment number to read only
Case "CorrectiveAction"
DetailsField.ItemStyle.Wrap = True
DetailsField.ItemStyle.Height = 150
DetailsField.ItemStyle.Width = 150
DetailsField.ItemStyle.VerticalAlign =
VerticalAlign.Top
DetailsField.ControlStyle.CssClass =
"WrapText" 'not working yet
End Select
DetailsViewAudit.Fields.Add(DetailsField)
Case 2 'check box field
DetailsCheckBox = New CheckBoxField
DetailsCheckBox.DataField = drAuditFormat(4)
DetailsCheckBox.HeaderText = drAuditFormat(5)
DetailsCheckBox.Text = "Comply"
DetailsViewAudit.Fields.Add(DetailsCheckBox)
End Select
Loop
drAuditFormat.Close()
PlaceHolderDetails.Controls.Add(DetailsViewAudit)
Dim keyArray() As String = {"UniqueKey"}
DetailsViewAudit.DataKeyNames = keyArray
DetailsViewAudit.AutoGenerateEditButton = True
DetailsViewAudit.AutoGenerateRows = False
DetailsViewAudit.Fields(2).HeaderStyle.Width = 6000
DetailsViewAudit.Fields(2).ItemStyle.Width = 300
DetailsViewAudit.CellPadding = 0
DetailsViewAudit.CellSpacing = 1
SqlDataSourceDetail.ConnectionString =
("MyDataSource") SqlDataSourceDetail.SelectCommandType
= SqlDataSourceCommandType.Text
SqlDataSourceDetail.SelectCommand = "SELECT * FROM [" &
TypeName & "] where AssessmentNumber='" & AuditNumber & "'"
SqlDataSourceDetail.UpdateCommandType =
SqlDataSourceCommandType.Text
'finalize update string
UpdateString = Mid(UpdateString, 1, Len(UpdateString) - 1) & "
WHERE AssessmentNumber='" & AuditNumber & "'"
SqlDataSourceDetail.UpdateCommand = UpdateString
DetailsViewAudit.DataSourceID = "SqlDataSourceDetail"
'DetailsViewAudit.DataBind() 'not required
AddHandler DetailsViewAudit.ModeChanging, AddressOf
DetailsViewAudit_ModeChanging
AddHandler DetailsViewAudit.ItemUpdating, AddressOf
DetailsViewAudit_ItemUpdating
AddHandler DetailsViewAudit.ItemUpdated, AddressOf
DetailsViewAudit_ItemUpdated