C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






DropdownList's selected text into TextBox


Posted Date: 29 Aug 2008    Resource Type: Articles    Category: Web Applications

Posted By: Ritesh N. Jain       Member Level: Gold
Rating:     Points: 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  
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: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use