In my application there 10 dropdownlists are there in
plz tell the code for it.
thanks.
7 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Gohil JayendrasinhPosted Feb 24, 2012, 12:00 AM
I think you have not requirement of hide the drop down
1) Create One Dropdown.
2) Put Placeholder on your .aspx page.
3) On selected Event identify how many dropdown do
you want?
4) Create Dynamic Dropdown control and add control to Placeholder.
Gunti DilipPosted Feb 24, 2012, 9:26 AM
SenthilkumarPosted Feb 23, 2012, 11:40 PM
Step 1: Design All the drop down and do not use the different drop down for different purpose. Calculate the maximum number of drop downs required. You can assign the different data source to the same control...
Step 2: Set the visible false to the unwanted drop down initially. Set the data source to the first control and try to use the DataTextField and DataValueField...Because the DataTextField should be used to display text and DataValueField is unique value.
Step3: Write the indexchanged event to the dropdown and enable the autopostback=true property. Then write the logics to get the value from the selected dropdown and populate the value to the subsequent dropdown and make that drop down as visible.
I would suggest you to use the update panel from the Ajax. Because it will be fast to render and avoid the post back. Otherwise it will take too much time to load and render every time when you select the drop down control.
Pramod Kumar NandagiriPosted Feb 23, 2012, 11:36 PM
such case server side coding is necessary other wise client side coding can be done
Jignesh TrivediPosted Feb 23, 2012, 10:35 PM
Agree with pramod.
Only one thing wat add,
Hide show logic , you can also write using JAVA SCRIPT or JQuery,
it reduce ur server call. hence increace performance.
Pramod Kumar NandagiriPosted Feb 23, 2012, 11:21 AM
First put all dropdown's visiblity false in page_load event except first drop down
then set every drop down visibility true in it's previous drop down selected index changed event like below
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList2.Visible = false;
...
...
DropDownList10.Visible = false;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Visible = true;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3.Visible = true;
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList4.Visible = true;
}
Pramod Kumar NandagiriPosted Feb 23, 2012, 11:14 AM
In each dropdown's selected index changed event the other drop down bind will occur
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.DataSource = datatable;
DropDownList1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//write sql query based on first drop down selected text or selected value
string strsql = "Select * from table where coulumn=" + DropDownList1.SelectedItem.Text;
...
... //code to fill datatable2
...
DropDownList2.DataSource = datatable2;
DropDownList2.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string strsql = "Select * from table where coulumn=" + DropDownList2.SelectedItem.Text;
...
... //code to fill datatable3
...
DropDownList3.DataSource = datatable3;
DropDownList3.DataBind();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
string strsql = "Select * from table where coulumn=" + DropDownList3.SelectedItem.Text;
...
... //code to fill datatable4
...
DropDownList4.DataSource = datatable;
DropDownList4.DataBind();
}
I hope you would understand...