Click here to Skip to main content
13,257,667 members (78,239 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have a dropdownlist and a text box.

Assume dropdownlist is having all country names .And if a user selects
India then its respective states should be displayed in the text box.

Can someone please help me to do this.

Posted 9-Apr-13 22:58pm
Anurag Sinha V 10-Apr-13 4:21am
On the SelectedIndexChanged event of the dropdownlist, bind your textbox to a datasource which will be basically a datatable having the results from your SQL table. these results wil;l be actuallt the names of the states.
Try it. It will work.

Suman Agnihotri 3 10-Apr-13 4:25am
ok thanks i will try
Anurag Sinha V 10-Apr-13 4:26am
Suman Agnihotri 3 10-Apr-13 5:10am
protected void newsubgrpddl_SelectedIndexChanged(object sender, EventArgs e)



private void getData(string grades)
DataTable dt = new DataTable();
string connectionString = ConfigurationManager.AppSettings["ApplicationServices"];
SqlConnection myconnection = new SqlConnection(connectionString);
SqlCommand sqlCmd = new SqlCommand("SELECT * from Admin_SubjectGroups WHERE SubjectGroupName = @SubjectGroupName", myconnection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlCmd.Parameters.AddWithValue("@SubjectGroupName", subgrptxtbox.Text);
if (dt.Rows.Count > 0)
subprefixtxtbox.Text = dt.Rows[0]["subprefixtxtbox"].ToString();

my tables:


AuthorityCode int not null
SubjectGroupid int not null
SubjectGroupName nvarchar(50)


SubjectGroupid not null
subjectprefix nvarchar(50)

Please can you help.. I have just tried the above code but its not displaying anything in the text boxwhen i select a value from dropdown list. Thanks
Anurag Sinha V 10-Apr-13 5:13am
Hey Mate,
right now i'm in offc fighting with a piece of code..i will work upon it and will send you the code. If you are ok, you can send me your email id and i will try to send you the working code by night. And its appreciable to see that you have tried something..Keep coding..

Anurag Sinha V 10-Apr-13 5:21am
Kool..i will try to send a working model...

Anurag Sinha V 10-Apr-13 5:25am
Yes you are total free to do so..go ahead.. :)

Anurag Sinha V 10-Apr-13 5:22am
Ohh that case..i hv copied can go ahead and delete it...

Suman Agnihotri 3 10-Apr-13 5:26am
Anurag Sinha V 10-Apr-13 5:27am

Anurag Sinha V 10-Apr-13 12:57pm
just FYI..have mailed u the sample code..have a look..


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100