Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
GridView1.DataSource = GetData("SELECT queHappy FROM tb_quehappy")
GridView1.DataBind()
End If
End Sub
Private Function GetData(ByVal query As String) As DataSet
Dim conString As String = strCon
Dim cmd As New MySqlCommand(query)
Using con As New MySqlConnection(conString)
Using sda As New MySqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet()
sda.Fill(ds)
Return ds
End Using
End Using
End Using
End Function
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim ddlCountries As DropDownList
ddlCountries = CType(e.Row.FindControl("ddlCountries"), DropDownList))
ddlCountries.DataSource = GetData("SELECT valueHappy,valueNameHappy FROM tb_valueHappy")
ddlCountries.DataTextField = "valueNameHappy"
ddlCountries.DataValueField = "valueHappy"
ddlCountries.DataBind()
ddlCountries.Items.Insert(0, New ListItem("Please select"))
Dim valueHappy As String = CType(e.Row.FindControl("lblCountry"), Label).Text
End If
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
Dim chkCusID As CheckBox
Dim lblID As Label
Dim i As Integer
lblText.Text = ""
For i = 0 To myGridView.Rows.Count - 1
chkCusID = myGridView.Rows(i).FindControl("chkCustomerID")
lblID = myGridView.Rows(i).FindControl("lblCustomerID")
IF chkCusID.Checked = True Then
'*** Have lblID.Text ***'
Me.lblText.Text = Me.lblText.Text & "<br>" & lblID.Text
End IF
Next
End Sub