Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i have 3 tables
1. state(state_id,state_name) state_id PK,Identity specification
2.city (city_id,city_name.state_id) city_id
Posted
Comments
OriginalGriff 2-Feb-13 5:34am    
And?
You forgot the question!
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
[no name] 2-Feb-13 5:41am    
Seems you've not read question in Subject...
shivani 2013 2-Feb-13 6:30am    
i am sorry i couldnt write whole code,,sry for ur valuable time .pls see that
[no name] 2-Feb-13 6:57am    
Elaborate it..

Your Question is not clear. But as per my understanding you want to bind the database values to DropDownList..? right...?


for that fetch the information from DataBase , and then store that information in DataSet and bind that DataSet to DropDownList.


Ex:

C#
DataSet ds=// fetch Data from DB;

ddl.DataSource=ds;
ddl.DataTextField="Name";
ddl.DataValueField="Id";
ddl.DataBind();


if you want more information regarding this you can search in google.
In google you get more results regarding this topic...
 
Share this answer
 
Comments
shivani 2013 2-Feb-13 6:30am    
i am sorry i couldnt write whole code,,sry for ur valuable time .pls see that
C#
// This is I've done for Document Type, based on it you can do it for your own query.

EditDocTypeDropDown.DataSource = bc.FillDocTypeDropDown();  // Fetch value for DropDown from Database
EditDocTypeDropDown.DataValueField = "type_id";
EditDocTypeDropDown.DataTextField = "type";
EditDocTypeDropDown.DataBind();
 
Share this answer
 
Comments
shivani 2013 2-Feb-13 6:30am    
i am sorry i couldnt write whole code,,sry for ur valuable time .pls see that
SqlDataSource sqlDS = new SqlDataSource();
        sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings[0].ToString();
        sqlDS.SelectCommand = "select state_id,state_name from State";
        form1.Controls.Add(sqlDS);

        DropDownList ddl = new DropDownList();
        ddl.ID = "dddlState";
        ddl.DataSource = sqlDS;
        ddl.DataTextField = "state_name";
        ddl.DataValueField = "state_id";
        form1.Controls.Add(ddl);


on the Change Index event of dd1 you can put the code

SqlDataSource sqlDS = new SqlDataSource();
        sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings[0].ToString();
        sqlDS.SelectCommand = "select city_id,city_name from city where state_id='+dddlState.Value.Text()+"'";
        form1.Controls.Add(sqlDS);

        DropDownList dd2 = new DropDownList();
        dd2.ID = "dddlCity";
        dd2.DataSource = sqlDS;
        dd2.DataTextField = "City_name";
        dd2.DataValueField = "city_id";
        form1.Controls.Add(dd2);
 
Share this answer
 

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