I need to get the selected value from a gridview dropdownlist selectedvalue

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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 = &quot;Data Source=ServerName;Initial Catalog=Catalog;Persist Security Info=True;User ID=username;Password=password&quot;
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(&quot;ReasonDropDown&quot;)

dd.SelectedValue = What goes here please

Dim InsertString As String = &quot;INSERT INTO DatabaseTable(Unit,Reason,IncidentDate,OOSID,FlagTrue) &quot; _
&amp; &quot;Values (&quot; &amp; GridView1.Rows(index).Cells(2).Text &amp; &quot;,&quot; &amp; dd.SelectedValue &amp; &quot;,&quot; &amp; GridView1.Rows(index).Cells(1).Text &amp; &quot;,&quot; &amp; GridView1.Rows(index).Cells(4).Text &amp; &quot;,1)&quot;

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
 
Back
Top