TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
aditya immadi
NA
215
24.1k
IN Country and states drop dows ....states or not populating
May 26 2016 3:58 AM
Hai all i wrote this one for country and states binding in dropdown countries dropdown is working fine but states drop down is not populating
protected void BindDdlCountry()
{
SqlConnection con = new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Tb_country", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DdlCountry.DataSource = ds;
DdlCountry.DataTextField = "Country";
DdlCountry.DataValueField = "Id";
DdlCountry.DataBind();
DdlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
DdlState.Items.Insert(0, new ListItem("--Select--", "0"));
}
___for States Dropdown__
int StateID = Convert.ToInt32(DdlCountry.SelectedIndex);
SqlConnection con = new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Tb_State where Country_Id_Pk='" + StateID + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DdlState.DataSource = ds;
DdlState.DataTextField = "StateName";
DdlState.DataValueField = "StateId";
DdlState.DataBind();
and i never assign any of primary keys in my tables
hope someone helps me
TIA
Reply
Answers (
1
)
Benifits, in which senario & when to use AutoMapper in MVC?
How to load dropdownbox with 2 value?