Set value of dropdown list in datagrid

E

Eric J.

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?
 
T

Thusith Kathaluwage

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)
Con.Open()
Dim drMovie As SqlDataReader = cmd.ExecuteReader

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

End With
Con.Close()
End If

End Sub

Hope this helps

Thusith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top