C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

DropdownList's selected text into TextBox


Posted Date: 29 Aug 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Ritesh N. JainMember Level: Gold    
Rating: 1 out of 5Points: 7



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.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
DropdownList's selected text into TextBox  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Javascript ToolTip
Previous Resource: Printing contents of controls in .Net
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use