CochiseCounty
asked on
set checked = true for checkboxlist
I have this checkboxlist from a database table with 3 fields ID, Assignee, Status
cmdSQL = New SqlCommand("sp_RetrieveAss igneeBySus pense", cnnST)
cmdSQL.CommandType = CommandType.StoredProcedur e
cmdSQL.Parameters.Add("@Su spenseID", Session("ID"))
Reader = cmdSQL.ExecuteReader()
chkStatus.DataSource = Reader
chkStatus.DataTextField = Reader("Assignee")
chkStatus.DataValueField = Reader("ID")
chkStatus.DataBind()
If I want to do something like if the field 'status' in my database is 'completed' then that checkbox should be checked as default. How do I do that? Thanks for help
cmdSQL = New SqlCommand("sp_RetrieveAss
cmdSQL.CommandType = CommandType.StoredProcedur
cmdSQL.Parameters.Add("@Su
Reader = cmdSQL.ExecuteReader()
chkStatus.DataSource = Reader
chkStatus.DataTextField = Reader("Assignee")
chkStatus.DataValueField = Reader("ID")
chkStatus.DataBind()
If I want to do something like if the field 'status' in my database is 'completed' then that checkbox should be checked as default. How do I do that? Thanks for help
ASKER
I did that but the chkStatus listbox doesn't show up in my page
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hai,
Instead of DataReader just try dataset
Dim myAdapter As New SqlClient.SqlDataAdapter
Dim myDataSet As New DataSet
myAdapter.Fill(myDataSet, "myTable")
chkStatus.DataSource = myDataSet.Tables(0)
chkStatus.DataTextField = "Assignee"
chkStatus.DataValueField = "id"
chkStatus.DataBind()
'Loop through the dataset and check whether staus is completed if so just set selected property of the the corresponding ' checkbox in the list to True
For itemCounter As Integer = 0 To myDataSet.Tables(0).Rows.C ount - 1
With myDataSet.Tables(0).Rows(i temCounter )
If .Item("Status").ToString.T oLower = "completed" Then chkStatus.Items(itemCounte r).Selecte d = True
End With
Next
It works fine for me..
hope this will help u
Regards
Vinu
Instead of DataReader just try dataset
Dim myAdapter As New SqlClient.SqlDataAdapter
Dim myDataSet As New DataSet
myAdapter.Fill(myDataSet, "myTable")
chkStatus.DataSource = myDataSet.Tables(0)
chkStatus.DataTextField = "Assignee"
chkStatus.DataValueField = "id"
chkStatus.DataBind()
'Loop through the dataset and check whether staus is completed if so just set selected property of the the corresponding ' checkbox in the list to True
For itemCounter As Integer = 0 To myDataSet.Tables(0).Rows.C
With myDataSet.Tables(0).Rows(i
If .Item("Status").ToString.T
End With
Next
It works fine for me..
hope this will help u
Regards
Vinu
chkStatus.DataTextField = Reader("Assignee")
chkStatus.DataValueField = Reader("ID")
if Reader("Status")="complete
chkStatus.checked=true
end if
chkStatus.DataBind()