Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL
hi,
 
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.
 

Thanks
Posted 9-Apr-13 22:58pm
babli3793
Comments
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.
 
-Anurag
Suman Agnihotri 3 at 10-Apr-13 4:25am
   
ok thanks i will try
Anurag Sinha V at 10-Apr-13 4:26am
   
kool
Suman Agnihotri 3 at 10-Apr-13 5:10am
   
protected void newsubgrpddl_SelectedIndexChanged(object sender, EventArgs e)
{
 
getData(newsubgrpddl.SelectedItem.Text);
 

}
 
private void getData(string grades)
{
DataTable dt = new DataTable();
string connectionString = ConfigurationManager.AppSettings["ApplicationServices"];
SqlConnection myconnection = new SqlConnection(connectionString);
myconnection.Open();
SqlCommand sqlCmd = new SqlCommand("SELECT * from Admin_SubjectGroups WHERE SubjectGroupName = @SubjectGroupName", myconnection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlCmd.Parameters.AddWithValue("@SubjectGroupName", subgrptxtbox.Text);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
subprefixtxtbox.Text = dt.Rows[0]["subprefixtxtbox"].ToString();
}
myconnection.Close();
}
 
my tables:
 
Admin_SubjectGroups:
 
AuthorityCode int not null
SubjectGroupid int not null
SubjectGroupName nvarchar(50)
 

Admin_Subjects
 
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
Anurag Sinha V at 10-Apr-13 5:21am
   
Kool..i will try to send a working model...
 
-Anurag
Anurag Sinha V at 10-Apr-13 5:25am
   
Yes you are total free to do so..go ahead.. :)
 
-Anurag
Anurag Sinha V at 10-Apr-13 5:22am
   
Ohh ok..in that case..i hv copied it..you can go ahead and delete it...
 
-ANurag
Suman Agnihotri 3 at 10-Apr-13 5:26am
   
thanks
Anurag Sinha V at 10-Apr-13 5:27am
   
Np....enjoy
 
-ANurag
Anurag Sinha V at 10-Apr-13 12:57pm
   
just FYI..have mailed u the sample code..have a look..
 
-ANurag

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

  Print Answers RSS
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2014
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