Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
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
Comments
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.

-Anurag
babli3 10-Apr-13 4:25am    
ok thanks i will try
Anurag Sinha V 10-Apr-13 4:26am    
kool
babli3 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 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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900