I am facing problem with drop down list.I am controlling from from one more drop down list.I need to clear
all the items present in second drop down list and add new items my following code is not working .
int n = Convert.ToInt32(DropDownList1.SelectedIndex);
if (n == 0)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("B.E");
DropDownList2.Items.Add("M.C.A");
DropDownList2.Items.Add("M.B.A");
}
if (n == 1)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("Software engineer");
DropDownList2.Items.Add("Manager");
DropDownList2.Items.Add("Sales excetive");
DropDownList2.Items.Add("System operator");
DropDownList2.Items.Add("Graphics engineer");
}
WHY it is not working?
Suggest me the way.
Satyapriya NayakPosted Oct 4, 2011, 6:14 AM
Try this
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("0");
DropDownList1.Items.Add("1");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//Make sure that Autopostback property to True
int n = Convert.ToInt32(DropDownList1.SelectedIndex);
if (n == 0)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("B.E");
DropDownList2.Items.Add("M.C.A");
DropDownList2.Items.Add("M.B.A");
}
if (n == 1)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("Software engineer");
DropDownList2.Items.Add("Manager");
DropDownList2.Items.Add("Sales excetive");
DropDownList2.Items.Add("System operator");
DropDownList2.Items.Add("Graphics engineer");
}
}
}
Thanks
If this post helps you mark it as answer
maheswar reddyPosted Oct 4, 2011, 5:29 AM
But It sis not working .... Still I am facing same error ...
Hemant KumarPosted Oct 4, 2011, 4:41 AM