Hi guys, I careted dynamic drpdown in asp page. when i change dropdown value i want to reload the page. when realod the page i don't relod dropdown. in drop down i just want chaged value. can any one explain how to this one and can any one give samplecode for this one ASAP? Example: when page load i have some x value. now selected another value some y. After that when i submit the page dropdown value comes x. But i want to display one y . Thanks
You can set the dropdownlist's AutoPostBack property to true to cause the post back. Then simply only bind the drop down data if it is not a post back. ASP.NET has a built in variable for this called IsPostBack. this.DropDown1.AutoPostBack = true; if(!IsPostBack) { BindDropDownListData(); } Code (markup):
Thanks for your reply! I am new to asp. In asp can give some complete sample code.(with dropdown creation,binding, and selectedindex event) Thanks
protected void Page_Load( object sender, EventArgs e ) { If(!IsPostBack) BindDropDown(); BindData(); } private void BindDropDown() { this.ddCats.DataSource = GetDataToBind(); this.ddCats.DataBind(); } private void BindData() { //bind the data on your page } Code (markup):
Within the BindData() event you can bind other controls on the page using if(this.DropDownMenu.SelectedIndex == 0) dothis; Code (markup): or if(this.DropDownMenu.SelectedValue = "Red") dothis; Code (markup):