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 Munshi51 reputationPosted Feb 16, 2012, 4:16 AM EST
===========================================================
.aspx code
=============================
Abdullah Munshi51 reputationPosted Feb 16, 2012, 1:39 AM EST
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.
Gunti Dilip47 reputationPosted Feb 16, 2012, 2:57 AM EST
Abdullah Munshi51 reputationPosted Feb 16, 2012, 3:25 AM EST
dv.RowFilter="FieldName1="+DropDownList1.SelectedValue+"AND "FieldName2=" +DropDownList1.SelectedValue;
DropDownList3.DataTextField="abc";
DropDownList3.DataValueField="xyz";
DropDownList3.DataSource=dv;
DropDownList3.DataBind();
Gunti Dilip47 reputationPosted Feb 16, 2012, 3:34 AM EST
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 Munshi51 reputationPosted Feb 16, 2012, 3:42 AM EST
Gunti Dilip47 reputationPosted Feb 16, 2012, 3:48 AM EST
Gunti Dilip47 reputationPosted Feb 16, 2012, 4:53 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts