473,545 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drop Down Lists Query

Hi,

I new to C# so please forgive me if this is simple. I've got 2 drop
down lists the first is hard coded with data where as the second is
populated from a database. The options that appear in the second should
be determined by what is selected in the first drop down list. When the
page loads it automatically populates the second list with the default
value via a proceedure:

public void popDDL(string dbName)
{

string strConn;
string strSQL;
strConn = "SERVER=localho st,1433; DATABASE="+dbNa me+"; user
id=HMI_User; password=HMI_Us er; Language=Britis h";
strSQL = @"SELECT name FROM table1 ORDER BY name";
conn = new SqlConnection( strConn );

try
{
conn.Open();
cmdSelect = new SqlCommand(strS QL, conn);
SqlDataReader dtr = cmdSelect.Execu teReader();
if (dtr.HasRows)
{
ddlMachine.Data Source = dtr;
ddlMachine.Data TextField = "name";
ddlMachine.Data ValueField = "name";
ddlMachine.Data Bind();
}
}
catch (Exception ex)
{
lblError.Text = "Error! Could not generate search information!
"+ex;
}
finally
{
conn.Close();
}
}

In the first drop down list the values are the database names. What I'm
am trying to do is something like:
onClick(popDDL( "databasename") )
so the page is refreshed with the new data however I'm not sure how to
do it in C#. Any help would be appreciated.

Thanks

Simon

Jan 27 '06 #1
1 2089
This is simple in .NET but you must remember that there will be a post back
to the server. In the DropDownList control add this:

AutoPostBack="T rue"
OnSelectedIndex Changed="FirstD ropDownSelectio nChange"

Where FirstDropDownSe lectionChange is the method name that refreshes the 2nd
drop down.

--
adi
"accyboy198 1" wrote:
Hi,

I new to C# so please forgive me if this is simple. I've got 2 drop
down lists the first is hard coded with data where as the second is
populated from a database. The options that appear in the second should
be determined by what is selected in the first drop down list. When the
page loads it automatically populates the second list with the default
value via a proceedure:

public void popDDL(string dbName)
{

string strConn;
string strSQL;
strConn = "SERVER=localho st,1433; DATABASE="+dbNa me+"; user
id=HMI_User; password=HMI_Us er; Language=Britis h";
strSQL = @"SELECT name FROM table1 ORDER BY name";
conn = new SqlConnection( strConn );

try
{
conn.Open();
cmdSelect = new SqlCommand(strS QL, conn);
SqlDataReader dtr = cmdSelect.Execu teReader();
if (dtr.HasRows)
{
ddlMachine.Data Source = dtr;
ddlMachine.Data TextField = "name";
ddlMachine.Data ValueField = "name";
ddlMachine.Data Bind();
}
}
catch (Exception ex)
{
lblError.Text = "Error! Could not generate search information!
"+ex;
}
finally
{
conn.Close();
}
}

In the first drop down list the values are the database names. What I'm
am trying to do is something like:
onClick(popDDL( "databasename") )
so the page is refreshed with the new data however I'm not sure how to
do it in C#. Any help would be appreciated.

Thanks

Simon

Jan 27 '06 #2

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

Similar topics

2
2648
by: Phil Longworth | last post by:
Im very new to Access 97 and Im sure I should be able to do this but cant work out how. Im bulding a database for my stamp collection. I have two tables; one with details of all the individual stamps, and one with details of covers/envelopes the stamps are fixed to. Each indivdual stamp has a specific reference number (not an auto-number). ...
0
1726
by: Giulio Santorini | last post by:
Hi, I've got two drop down list controls. When I select a value from the first one I fill the second one. And when I select a value from the second one I would like to fill another control. But after have choose from the first control and filled the second... when I select something from the second control I have not the post back event! I...
3
14208
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want to insert the values and text to each drop down list. So i want to create a script that populates a certain Drop Down List with certain values...
13
5220
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data structures? Thanks for any hints, Leszek Taratuta
0
905
by: JohnZing | last post by:
Hi, i have a list of drop down lists. The first one is populated with a Select Query The Second one is populated with a select query where ParentID is the first drop down list selected value The Third.... and so on... The problem is: How can I handle the events from the different drop down lists?
2
12599
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will select any skill in 1st drop down list then i'll select % of this skill in the 2nd list box , based on the percentage i've selected in the 2nd list...
7
6303
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want to insert the values and text to each drop down list. So i want to create a script that populates a certain Drop Down List with certain values...
3
7337
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the document selected (my application uses the BusinessObjects Java Web Services SDK) The 2nd list is dependent on the 1st, while the 3rd list is...
3
5864
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I analyze each word and rebuild the text string as a combination of correct text (not misspelled) and a drop down list offering suggestions in place of...
0
7415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.