In the aspx page, i have
<asp:dropdownlist id="dListOfficeCode" runat="server"
DataTextField="Description" DataValueField="OfficeCode" />
In Codebehind this is how i bind:
myConnection = New SqlConnection(conStr)
Dim myCommand As SqlCommand = New SqlCommand("Select OfficeCode
as OfficeCode, Description as Description from OfficeCode order by
Description", myConnection)
Dim myDataReader As SqlDataReader
Try
myConnection.Open()
myDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
dListOfficeCode.DataSource = myDataReader
dListOfficeCode.DataBind()
dListOfficeCode.Items.FindByValue(
Catch myException As Exception
Response.Write("An error has occurred: " &
myException.ToString())
Finally
If Not myDataReader Is Nothing Then
myDataReader.Close()
End If
dListOfficeCode.SelectedIndex = 0
End Try
Would this help?
Manny
"Karl Seguin" wrote:
yourDropDownList.SelectedIndex =
yourDropDownList.IndexOf(yourDropDownList.Items.Fi ndByValue("CanadasValue"))
without much code it's hard to help you any further...but it's something
like that...."CanadasValue" would be the value part of the item bound to the
dropdown..
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Manny Chohan" <Ma*********@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com... Hi Guys, I have a table with country field for each user. Now when i go
into modify mode, i load the dropdown list with all the countries from the
datbase. I need to preselect the index for the appropriate country
assigned for that user. Lets say if i set Tom for Canada, and when i bring his
record in modify mode, i should see canada instead of first county in the drop
down list.
Can this be done?
Thanks in advane.
Manny