Hi,
In my application there are three dropdownlist are there if user selects the first and second dropdowns the data should be binded into third dropdownlist without using SQL or any database only through (datatable)?
Plz Tell the code for it....
Thanks.
Loading
Abdullah MunshiPosted Feb 16, 2012, 9:16 AM
===========================================================
.aspx code
=============================
Gunti DilipPosted Feb 16, 2012, 9:53 AM
Gunti DilipPosted Feb 16, 2012, 8:48 AM
Abdullah MunshiPosted Feb 16, 2012, 8:42 AM
Gunti DilipPosted Feb 16, 2012, 8:34 AM
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("ID", typeof(string)));
dt.Rows.Add("Wholesale Area", "wa");
dt.Rows.Add("Region", "reg");
dt.Rows.Add("Notification Group", "ng");
ddlSendMsgBy.DataSource = dt;
ddlSendMsgBy.DataTextField = dt.Columns[0].ToString();
ddlSendMsgBy.DataValueField = dt.Columns[1].ToString();
ddlSendMsgBy.DataBind();
DataTable dt1 = new DataTable();
dt1.Columns.Add(new DataColumn("Name1", typeof(string)));
dt1.Columns.Add(new DataColumn("ID1", typeof(string)));
dt1.Rows.Add("All (non-dealers)", "A");
dt1.Rows.Add("Branded Jobber", "B");
dt1.Rows.Add("Unbranded Jobber", "U");
ddlPriceType.DataSource = dt1;
ddlPriceType.DataTextField = dt1.Columns[0].ToString();
ddlPriceType.DataValueField = dt1.Columns[1].ToString();
ddlPriceType.DataBind();
DataTable dt2 = new DataTable();
dt2.Columns.Add(new DataColumn("Name2", typeof(string)));
dt2.Columns.Add(new DataColumn("ID2", typeof(string)));
dt2.Columns.Add(new DataColumn("ID", typeof(string)));
dt2.Columns.Add(new DataColumn("ID1", typeof(string)));
dt2.Rows.Add("1234", "1","wa","A");
dt2.Rows.Add("ASDF", "A","reg","B");
dt2.Rows.Add("9999", "9","ng","U");
}
Abdullah MunshiPosted Feb 16, 2012, 8:25 AM
dv.RowFilter="FieldName1="+DropDownList1.SelectedValue+"AND "FieldName2=" +DropDownList1.SelectedValue;
DropDownList3.DataTextField="abc";
DropDownList3.DataValueField="xyz";
DropDownList3.DataSource=dv;
DropDownList3.DataBind();
Gunti DilipPosted Feb 16, 2012, 7:57 AM
Abdullah MunshiPosted Feb 16, 2012, 6:39 AM
First fill the data in a datatable.
Then,
Dataview dv=new DataView(dataTable);
//dataTable will be your datatable from which you will filter records
dv.RowFilter="FieldName="+DropDownList1.SelectedValue;
DropDownList2.DataTextField="abc";
DropDownList2.DataValueField="xyz";
DropDownList2.DataSource=dv;
DropDownList2.DataBind();
I think you need to do something like this.