01.
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
02.
If
Not
IsPostBack
Then
03.
GridView1.DataSource = GetData(
"SELECT queHappy FROM tb_quehappy"
)
04.
GridView1.DataBind()
05.
End
If
06.
End
Sub
07.
08.
Private
Function
GetData(
ByVal
query
As
String
)
As
DataSet
09.
Dim
conString
As
String
= strCon
10.
Dim
cmd
As
New
MySqlCommand(query)
11.
Using con
As
New
MySqlConnection(conString)
12.
Using sda
As
New
MySqlDataAdapter()
13.
cmd.Connection = con
14.
sda.SelectCommand = cmd
15.
Using ds
As
New
DataSet()
16.
sda.Fill(ds)
17.
Return
ds
18.
End
Using
19.
End
Using
20.
End
Using
21.
End
Function
22.
23.
Protected
Sub
OnRowDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewRowEventArgs)
24.
If
(e.Row.RowType = DataControlRowType.DataRow)
Then
25.
Dim
ddlCountries
As
DropDownList
26.
ddlCountries =
CType
(e.Row.FindControl(
"ddlCountries"
), DropDownList))
27.
ddlCountries.DataSource = GetData(
"SELECT valueHappy,valueNameHappy FROM tb_valueHappy"
)
28.
ddlCountries.DataTextField =
"valueNameHappy"
29.
ddlCountries.DataValueField =
"valueHappy"
30.
ddlCountries.DataBind()
31.
32.
ddlCountries.Items.Insert(0,
New
ListItem(
"Please select"
))
33.
34.
Dim
valueHappy
As
String
=
CType
(e.Row.FindControl(
"lblCountry"
), Label).Text
35.
36.
End
If
37.
End
Sub