Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Set value of dropdown list in datagrid

Thread Tools

Set value of dropdown list in datagrid

Eric J.
Posts: n/a
I have a datagrid with a column containing a label and a dropdown (for the edit mode). When I choose edit, the dropdown should select the value corresponding to the label. Now it always selects the first item in the list.
I have no idea where I can put code for this. I tried without success in the OnEdit handler, but I cannot set the value of the dropdown list there.

Any suggestions?

Eric J. van Dorp
VanDorp Educatief
Reply With Quote
Thusith Kathaluwage
Posts: n/a

maybe because you did not put your code inside IsPostBack checking. so
when you select the item in list server reloads the page with initialize
data with your slections. do include inside checking like this

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack = False Then
Dim Con As New SqlConnection(strConnectionString)
Dim cmd As New SqlCommand("Select MovID, MovTitle FROM
Movie", Con)
Dim drMovie As SqlDataReader = cmd.ExecuteReader

With ddlMovie
.DataSource = drMovie
.DataTextField = "MovTitle"
.DataValueField = "MovID"
.Items.Insert(0, "<-- Select -->")

End With
End If

End Sub

Hope this helps


*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
gridview control, trying to set selected value in a dropdown list Paul ASP .Net 3 06-26-2008 10:55 PM
Select (dropdown) list and set value based on table column mcauliffe ASP General 5 01-26-2007 10:03 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
ASP.NET Set selected value of Dropdown within Datagrid Jenna Alten ASP .Net 6 02-26-2005 04:12 AM
How to set background color of List item in dropdown list M. Craig ASP .Net Web Controls 0 11-12-2003 06:26 PM