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
Inżynier Umair
NA
134
10.5k
dropdownlist onselectedindexchanged event is not working
Aug 19 2016 2:45 PM
on page load the country dropdownlist is bind and working fine but after when i select the country than no state bind in state dropdownlist.
----------------------front end-----------------------------
<asp:DropDownList ID="ddlcountry" runat="server" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged" AutoPostBack="true" CssClass="form-control ddl"></asp:DropDownList>
<asp:DropDownList ID="ddlstate" runat="server" AutoPostBack="true" CssClass="form-control ddl"></asp:DropDownList>
--------------------------------code behind------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
getcountry();
}
}
protected void getcountry()
{
try
{
da = new SqlDataAdapter("select * from get_country", con);
ds = new DataSet();
da.Fill(ds);
ddlcountry.DataSource = ds;
ddlcountry.DataTextField = "conname";
ddlcountry.DataValueField = "conid";
ddlcountry.DataBind();
ddlcountry.Items.Insert(0, new ListItem("--Select--", "0"));
ddlstate.Items.Insert(0, new ListItem("--Select--", "0"));
}
catch (Exception ex)
{
Response.Write("error occurd :" + ex.Message.ToString());
}
finally
{
con.Close();
}
}
protected void ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int conid = Convert.ToInt32(ddlcountry.SelectedItem.Value.ToString());
da = new SqlDataAdapter("select stateid,statename from get_state where conid=" + conid, con);
ds = new DataSet();
da.Fill(ds);
ddlstate.DataSource = ds;
ddlstate.DataTextField = "statename";
ddlstate.DataValueField = "stateid";
ddlstate.DataBind();
ddlstate.Items.Insert(0, new ListItem("---Select State---", "0"));
if (ddlstate.SelectedValue == "0")
{
ddlcity.Items.Clear();
ddlcity.Items.Insert(0,new ListItem("---Select City---","0"));
}
}
catch(Exception ex)
{
Response.Write("error occurd :" + ex.Message.ToString());
}
finally
{
con.Close();
}
}
Reply
Answers (
5
)
A topic on to string function
about session in c# .net