hello,
I have a gridview with 2 checkbox lists; I'm editing/updating the database with my new comma delimited string of values. the first part, chkThursEvents, updates with no issues, the second one, chkFridayEvents, does not update at all- not sure what is wrong with the code... help!
I have a gridview with 2 checkbox lists; I'm editing/updating the database with my new comma delimited string of values. the first part, chkThursEvents, updates with no issues, the second one, chkFridayEvents, does not update at all- not sure what is wrong with the code... help!
Code:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim showid As Integer
showid = GridView1.DataKeys(e.RowIndex).Value
Dim cblist2 As CheckBoxList
cblist2 = CType(GridView1.Rows(e.RowIndex).FindControl("chkThursEvents"), CheckBoxList)
Dim i2
Dim SendString2 As String = ""
For i2 = 0 To cblist2.Items.Count - 1
If cblist2.Items(i2).Selected = False Then
lblEVThurs.Text = SendString2
GridView1.DataBind()
End If
If cblist2.Items(i2).Selected = True Then
SendString2 &= cblist2.Items(i2).Value.ToString + ","
lblEVThurs.Text = SendString2
Dim conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ENAPWebConnectionString").ConnectionString)
Dim upcommand As New SqlClient.SqlCommand
upcommand = conn.CreateCommand
upcommand.CommandType = CommandType.Text
upcommand.CommandText = "update tblVendorShowEvents set chkThursEvents='" & SendString2 & "' where showid=" & Trim(showid) & " "
conn.Open()
upcommand.ExecuteNonQuery()
conn.Close()
GridView1.DataBind()
End If
Next
Dim cblist As CheckBoxList
showid = GridView1.DataKeys(e.RowIndex).Value
cblist = CType(GridView1.Rows(e.RowIndex).FindControl("chkFridayEvents"), CheckBoxList)
Dim i
Dim SendString As String = ""
For i = 0 To cblist.Items.Count - 1
If cblist.Items(i).Selected = False Then
lblEVFri.Text = SendString
GridView1.DataBind()
End If
If cblist.Items(i).Selected Then
SendString &= cblist.Items(i).Value.ToString + ","
lblEVFri.Text = SendString
Dim conn1 As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ENAPWebConnectionString").ConnectionString)
Dim upcommand1 As New SqlClient.SqlCommand
upcommand1 = conn1.CreateCommand
upcommand1.CommandType = CommandType.Text
upcommand1.CommandText = "update tblVendorShowEvents set chkFridayEvents='" & SendString & "' where showid=" & Trim(showid) & " "
conn1.Open()
upcommand1.ExecuteNonQuery()
conn1.Close()
GridView1.DataBind()
End If
Next
End Sub