protected void DDLstate_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select City from Mst_City where State='"+DDLstate.SelectedValue+"'",con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Mst_City");
DDLcity.DataSource = ds;
DDLcity.DataBind();
}
here in above code data retrived when am debugging but it will show system.data.datarowview in dropdownlist when am change in state from state dropdownlist
Loading


Bhabani prasad Dash168 reputationPosted May 21, 2013, 8:51 PM EDT
protected void DDLstate_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select City from Mst_City where State='"+DDLstate.SelectedValue+"'",con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Mst_City");
DDLcity.DataSource = ds.Tables["Mst_City"];
// DDLcity.DataTextField = "City"; // This is text displayed
DDLcity.DataValueField = "City"; // This is the value returned
DDLcity.DataBind();
}
Pankaj PandeyRank #642 · 3.7K reputationPosted May 21, 2013, 8:55 PM EDT
try this...
protected void DDLstate_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select City from Mst_City where State='"+DDLstate.SelectedValue+"'",con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Mst_City");
DDLcity.DataSource = ds;
DDLcity.DataTextField="Mst_City";
DDLcity.DataValueField ="Mst_City";
DDLcity.DataBind();
}
or
protected void DDLstate_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select City from Mst_City where State='"+DDLstate.SelectedValue+"'",con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Mst_City");
DDLcity.DataTextField="Mst_City";
DDLcity.DataValueField ="Mst_City";
DDLcity.DataSource = ds;
DDLcity.DataBind();
}
I hope it will help you.
Mark as answered if helpfull
Satyapriya NayakRank #47 · 31.5K reputationPosted May 21, 2013, 10:22 PM EDT