EDN Admin
Well-known member
Please look over my code and see if you can help me retrieve the SelectedValue of the DropDownList. The DropDownList is inside a GridView column. The code works well but the dd.SelectedValue is always the first value in the list even if I choose a different
value in the list.
<pre class="prettyprint lang-vb Try
Dim strConnectionString As String = "Data Source=ServerName;Initial Catalog=Catalog;Persist Security Info=True;User ID=username;Password=password"
Dim conn As New SqlConnection(strConnectionString)
Dim strBuilder As New System.Text.StringBuilder
For index = 0 To GridView1.Rows.Count - 1
Dim dd As DropDownList = GridView1.Rows(index).Cells(0).FindControl("ReasonDropDown"
dd.SelectedValue = What goes here please
Dim InsertString As String = "INSERT INTO DatabaseTable(Unit,Reason,IncidentDate,OOSID,FlagTrue) " _
& "Values (" & GridView1.Rows(index).Cells(2).Text & "," & dd.SelectedValue & "," & GridView1.Rows(index).Cells(1).Text & "," & GridView1.Rows(index).Cells(4).Text & ",1)"
conn.Open()
Dim cmd As New SqlCommand(InsertString, conn)
cmd.ExecuteNonQuery()
conn.Close()
Next
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try[/code]
<br/>
Thanks in advance.<br/>
View the full article
value in the list.
<pre class="prettyprint lang-vb Try
Dim strConnectionString As String = "Data Source=ServerName;Initial Catalog=Catalog;Persist Security Info=True;User ID=username;Password=password"
Dim conn As New SqlConnection(strConnectionString)
Dim strBuilder As New System.Text.StringBuilder
For index = 0 To GridView1.Rows.Count - 1
Dim dd As DropDownList = GridView1.Rows(index).Cells(0).FindControl("ReasonDropDown"
dd.SelectedValue = What goes here please
Dim InsertString As String = "INSERT INTO DatabaseTable(Unit,Reason,IncidentDate,OOSID,FlagTrue) " _
& "Values (" & GridView1.Rows(index).Cells(2).Text & "," & dd.SelectedValue & "," & GridView1.Rows(index).Cells(1).Text & "," & GridView1.Rows(index).Cells(4).Text & ",1)"
conn.Open()
Dim cmd As New SqlCommand(InsertString, conn)
cmd.ExecuteNonQuery()
conn.Close()
Next
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try[/code]
<br/>
Thanks in advance.<br/>
View the full article