how to load specific value from dropdown list?

windows

Guest
Hi guys. i have an editable datagrid that has a edit button next to
each record.once i click on it goes to a new page and loads the specifc record in edit mode and allow me edit the values. one of the values is in drop down box as u can see in the pic below. The problem that i have it always loads the first value from drop downlist not value coresponding to the record. I be happy if some one help me fixt this problem.thanks


<!-- m --><a class="postlink" href="http://i5.photobucket.com/albums/y180/method007/datagrid.jpg">http://i5.photobucket.com/albums/y180/m ... tagrid.jpg</a><!-- m --> (datagrid pic)


<!-- m --><a class="postlink" href="http://i5.photobucket.com/albums/y180/method007/editmode.jpg">http://i5.photobucket.com/albums/y180/m ... itmode.jpg</a><!-- m --> (edit page)


<!-- m --><a class="postlink" href="http://i5.photobucket.com/albums/y180/method007/designview.jpg">http://i5.photobucket.com/albums/y180/m ... gnview.jpg</a><!-- m --> ( edit form in deisign view)

<!-- m --><a class="postlink" href="http://i5.photobucket.com/albums/y180/method007/19932c0e.jpg">http://i5.photobucket.com/albums/y180/m ... 932c0e.jpg</a><!-- m --> (db reletions)

my onload and update code :




Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
MyConnection = New SqlConnection("server=localhost;database=teniss2;uid=web;pwd=web;")
If Not IsPostBack Then


SqlSelectCommand1.Parameters(0).Value = Convert.ToInt16(Request.QueryString("match"))

SqlDataAdapter1.Fill(DataSet11, "matches")

MatchNolable.DataBind()

TeamNolable.DataBind()

TextBox1.DataBind()

TextBox2.DataBind()

SqlDataAdapter2.Fill(DataSetplayerteamMatches1, "Players")
Me.DropDownList1.DataBind()

End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyCommand As SqlCommand

Dim UpdateCmd As String = "Update Matches Set Teamno=" & Me.TeamNolable.Text & ", playerno=" & Me.DropDownList1.SelectedValue & ", won=" & Me.TextBox1.Text & ", lost=" & Me.TextBox2.Text & _
" Where MatchNo = " & MatchNolable.Text

MyCommand = New SqlCommand(UpdateCmd, MyConnection)
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyCommand.Connection.Close()
Server.Transfer("teamsandmatches.aspx")




End SubI cant see what datasources you are using to databind those elements... but I will assume they exist.

One thing you could do is get the index of the row that has the value you want from the dataset and then use the SelectedIndex property of the dropdownlist to assign the appropriate index.

Or use the SelectedValue method if you dont want to use an index.

Im sure there is a way to automate this but am unsure of how to do this.

Good Luck :)

Good Luck :)
 
Back
Top