Shortly: you need to create new
DropDownList
for each column (cell). ;)
For Each row As GridViewRow In Gridview1.Rows
For i = 1 to 2
Dim dl As New DropDownList()
cmd1.CommandText = "Select * from ClassRoom order by ClassRoom"
Dim dr2 = cmd1.ExecuteReader
dl.DataSource = dr2
dl.AppendDataBoundItems = True
dl.DataTextField = "ClassRoom"
dl.DataValueField = "ClassRoom"
dl.DataBind()
dl.SelectedItem.Text = ""
dr2.Close()
row.Cells(i).Controls.Add(dl)
Next i
Next
See similar question:
Re: GridView DropDownList programmatically add items on RowDataBound[
^]
I really do recommend to create
DropDownList
and set its properties on design time:
Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web Server Control[
^]