?
Solved

set checked = true for checkboxlist

Posted on 2006-05-25
4
Medium Priority
?
1,184 Views
Last Modified: 2012-05-05
I have this checkboxlist from a database table with 3 fields ID, Assignee, Status
cmdSQL = New SqlCommand("sp_RetrieveAssigneeBySuspense", cnnST)
        cmdSQL.CommandType = CommandType.StoredProcedure
        cmdSQL.Parameters.Add("@SuspenseID", 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
0
Comment
Question by:CochiseCounty
4 Comments
 
LVL 9

Expert Comment

by:Raju Srivatsavaye
ID: 16763789
does your query return the status field..if it does do something like this..

chkStatus.DataTextField = Reader("Assignee")
        chkStatus.DataValueField = Reader("ID")

if Reader("Status")="completed" then
 chkStatus.checked=true
end if
        chkStatus.DataBind()
0
 

Author Comment

by:CochiseCounty
ID: 16764077
I did that but the chkStatus listbox doesn't show up in my page
0
 
LVL 4

Accepted Solution

by:
RJeyaPrakash earned 750 total points
ID: 16766553
try something like

Dim d1 As SqlClient.SqlDataReader
Dim cmd As New SqlClient.SqlCommand

cmd.CommandText = "<yr command>"
cmd.Connection = sqlconnection1

            SqlConnection1.Open()

            d1 = cmd.ExecuteReader()

            Dim i As Integer
            While d1.Read
                CheckBoxList1.Items.Add(New ListItem(d1.Item("Assignee"), d1.Item("ID")))
                If (d1.Item("status") = "completed") Then
                    CheckBoxList1.Items(i).Selected = True
                End If
                i += 1
            End While

 d1.Close()
            SqlConnection1.Close()


regs
jp

0
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 16766632
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.Count - 1
            With myDataSet.Tables(0).Rows(itemCounter)
                If .Item("Status").ToString.ToLower = "completed" Then chkStatus.Items(itemCounter).Selected = True
            End With
        Next

It works fine for me..

hope this will help u

Regards
Vinu
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question