Many time one need to show the DropDownList's selected Text value to some textbox or other control,Normaly user end up using DropDownList's selectedindex change event without realising that this could affect the performance, by adding one more uncessary PostBack.To handle this type of thing one can always use DHTML.For e.g below code shows how just by adding once line of code, the Value of Dropdown list's (having ID as ddlMyList) selected text can be shown into TextBox control having ID or Name as TextBox1.
'Assuming ddlMyList is bound to Datatable dt having column MyName and MyValue ddlMyList.DataSource = dt ddlMyList.DataTextField = "MyName" ddlMyList.DataValueField = "MyValue" ddlMyList.DataBind()
Add onchange attribute for ddlMyListas
ddlMyList.Attribute.Add("onchange","document.getElementById('TextBox1').value = this.options[this.selectedIndex].text;")
In web based application it's always best practice to avoid uncessary PostBack,and above was one of the example where handling SelectedIndex event at server side will be as good as overkilling your application.
Hope this will help you to explore more about DHTML thing.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|