Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 .NET4 ASP.NET4.0
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 1-Feb-13 23:30pm
Comments
OriginalGriff at 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.
Krunal Rohit at 2-Feb-13 5:41am
   
Seems you've not read question in Subject...
shivani 2013 at 2-Feb-13 6:30am
   
i am sorry i couldnt write whole code,,sry for ur valuable time .pls see that
Krunal Rohit at 2-Feb-13 6:57am
   
Elaborate it..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
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...
  Permalink  
Comments
shivani 2013 at 2-Feb-13 6:30am
   
i am sorry i couldnt write whole code,,sry for ur valuable time .pls see that
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

// 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();
  Permalink  
Comments
shivani 2013 at 2-Feb-13 6:30am
   
i am sorry i couldnt write whole code,,sry for ur valuable time .pls see that
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

 
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);
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 640
1 OriginalGriff 431
2 Maciej Los 255
3 PIEBALDconsult 180
4 Bruno Sprecher 170
0 Sergey Alexandrovich Kryukov 11,069
1 OriginalGriff 5,743
2 Maciej Los 5,649
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web04 | 2.8.141030.1 | Last Updated 3 Feb 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