Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with datalist checkboxes

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
0
0
GB
I have the following code which takes the selected items from a datalist and adds them to a database.

Code:
For Each li As DataListItem In dlProperties.Items
            Dim cb As CheckBox = TryCast(li.FindControl("chkSelectRoom"), CheckBox)
            Dim lblRoom As Label = TryCast(li.FindControl("RoomID"), Label)
            Dim lblRoomType As Label = TryCast(li.FindControl("RoomTypeLabel"), Label)

            Dim RoomID As Integer = Convert.ToInt32(lblRoom.Text)
            Dim RoomType As String = Convert.ToString(lblRoomType.Text)


            If cb IsNot Nothing Then
                If cb.Checked Then


                    cmd.Parameters.Clear()
                    cmd.Parameters.AddWithValue("@RoomID", RoomID.ToString())
                    cmd.Parameters.AddWithValue("@RoomType", RoomType.ToString())


                    cmd.ExecuteNonQuery()


                    TextBox1.Text += RoomType.ToString()
                End If
            End If
        Next

This code works however when it is adding the RoomType it is only adding the first character. So for Single its adding S only.

Any ideas why?
Thanks
Andrew
 
First, no need to convert it to a string. Second, have you debugged. Step through the code where you get the label and make sure you are getting the correct control. Test the value(s) in the watch window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top