Pre-Checking checkboxes?

R

Roy

Hey all,
I have a "worker" page where users can click on checkboxes, fill in
notes, etc. I wish to "pre-check" the checkboxes if certain criteria are
met. I assume it must be done in the For loop shown below. The event in
this case is what event code is show in "event" field below.


Sub Binddata()
Dim myconn As New
SqlConnection("server=localhost;uid=name;pwd=password;database=test")
Dim tmpUID As Label
tmpUID = CType(Page.FindControl("uid"), Label)
myconn.Open()
Dim mycom As New SqlCommand("SELECT dates,note,event FROM L2_Test WHERE
cast(uid as nvarchar(40)) ='" & tmpUID.Text & "'", myconn)
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds, "one")
notesgrid.DataSource = newds.Tables("one").DefaultView
myconn.Close()
notesgrid.DataBind()

Dim row As DataRow
For Each row In newds.Tables("one").Rows


Next
End Sub
 
E

Eliyahu Goldin

Handle PreRender event for notesgrid. In the event go through every row,
check the criteria and set checkbox Checked property.

Eliyahu
 
R

Roy

Thanks for the comment Eliyahu... but I should've been more descriptive.
I've been operating on 3 or 4 hours sleep and it's taking it's toll. :)

The checkboxes are independent of the repeater ("notesgrid") and are
contained within a checkboxlist...
 
E

Eliyahu Goldin

Then handle PreRender event of the page. I mean after making up your sleep
hours :)

Eliyahu
 
R

Roy

I actually figured it out. Didn't use prerender, I stuck the code in the
page_load as shown below... Now my only trouble is getting the the
user-selected checks in the list to update the database! :)


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Page.IsPostBack = False Then
Dim gUID As String
gUID = Request.QueryString("id")
Dim tmpUID As Label
tmpUID = CType(Page.FindControl("uid"), Label)
tmpUID.Text = gUID

Dim myconn As New
SqlConnection("server=localhost;uid=name;pwd=password;database=pat")

Dim objComm As New SqlCommand("select event from l2_notes_box where uid
='" & tmpUID.Text & "'", myconn)

myconn.Open()
Dim myreader As SqlDataReader = objComm.ExecuteReader
While myreader.Read

Dim thisbox As ListItem =
CheckBoxList1.Items.FindByValue(myreader("event").ToString)
If thisbox.Value <> "" Then
thisbox.Selected = True
End If

End While
myconn.Close()
Binddata()

End If
End Sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top