473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question: Dropdown List Control

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
Nov 19 '05 #1
5 1075
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

Nov 19 '05 #2
On Fri, 18 Mar 2005 13:33:03 -0600, Manny Chohan
<Ma*********@discussions.microsoft.com> wrote:
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


A full example:
http://www.dotnetjunkies.com/HowTo/B...06419BD3D.dcik

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #3
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


Nov 19 '05 #4
JV
Funny. This is exactly what I was writing about (see post earlier today
starting with "IMHO")
"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

Nov 19 '05 #5
From what I told you, you should be able to figure it out:

dListOfficeCode.Items.SelectedIndex =
dListOffice.Items.IndexOf(dListOfficeCode.Items.Fi ndByValue("canada"))

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:30**********************************@microsof t.com...
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


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
0
by: john | last post by:
I have a dropdown with a SelectedIndexChanged event handler. I want the event to only get called if the dropdown list was the control that caused the postback. But if the value of the list is...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
0
by: progman417 | last post by:
I have a gridview with a dropdown list in an EditItemTemplate. I haven't set a width for the columns, so that they dynamically size according to the data displayed. When it goes into edit...
8
by: sheldonlg | last post by:
I am still improving my AJAX and I ran into something that I'm not sure how to do. I will have a page called where I will have a dropdown list at the top and a large display at the bottom. The...
0
by: michelle5613 | last post by:
I am trying to create a dropdown menu using ONLY css. I am having a problem. I need to get the headings a different color and font than the subheadings. I need the heading to be white and have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.