M
Martin
Hi,
Please can somebody explain how databinding is done on a checkbox list.
I have the follwoing code which I would have thought was enough to databind
a checkbox, but apparently not.
The data is coming from an sql server database
"Name" is a text feild
"Valid" is a bit field
da.Fill(ds)
chkList.DataSource = ds
chkList.DataTextField = "Name"
chkList.DataValueField = "Valid"
chkList.DataBind()
Now the code above does bind to a certain extent (the checkbox labels
contained in the name field all come through), but the selected property
which I would have though to come through from the "Valid" field does not.
can anybody tell me how to bind the valid field to my checkbox list so that
it is either checked or not, depending on the value from the database.
also, how can I bind a unique field to each checkbox so that when I come to
update in the database I know which field to update.
I managed to come up with code to partially do this
Dim i As Integer
For i = 0 To chkList.Items.Count - 1
If chkList.Items(i).Selected Then
Response.Write("Selected " & chkList.Items(i).Value &
"<br>")
Else
Response.Write("Not Selected " & chkList.Items(i).Value &
"<br>")
End If
Next
any help is appreciated.
cheers
martin
Please can somebody explain how databinding is done on a checkbox list.
I have the follwoing code which I would have thought was enough to databind
a checkbox, but apparently not.
The data is coming from an sql server database
"Name" is a text feild
"Valid" is a bit field
da.Fill(ds)
chkList.DataSource = ds
chkList.DataTextField = "Name"
chkList.DataValueField = "Valid"
chkList.DataBind()
Now the code above does bind to a certain extent (the checkbox labels
contained in the name field all come through), but the selected property
which I would have though to come through from the "Valid" field does not.
can anybody tell me how to bind the valid field to my checkbox list so that
it is either checked or not, depending on the value from the database.
also, how can I bind a unique field to each checkbox so that when I come to
update in the database I know which field to update.
I managed to come up with code to partially do this
Dim i As Integer
For i = 0 To chkList.Items.Count - 1
If chkList.Items(i).Selected Then
Response.Write("Selected " & chkList.Items(i).Value &
"<br>")
Else
Response.Write("Not Selected " & chkList.Items(i).Value &
"<br>")
End If
Next
any help is appreciated.
cheers
martin