Click here to Skip to main content
11,802,636 members (69,120 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL

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 21:58pm
Anurag Sinha V at 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 at 10-Apr-13 4:25am
ok thanks i will try
Anurag Sinha V at 10-Apr-13 4:26am
Suman Agnihotri 3 at 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 at 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 at 10-Apr-13 5:21am
Kool..i will try to send a working model...

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

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

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

Anurag Sinha V at 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
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,695
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
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