dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersSankar
Sunitha
cloud
Rajalingam
SivaSaiKrishna
Ashokkumar
er.g.ilango
Anu George
Krishna Kant
parameswaran
More...




Resources » Articles » ASP.NET/Web Applications


DropdownList's selected text into TextBox


Posted Date:     Category: ASP.NET/Web Applications    Rating: 1 out of 5
Author: Member Level: Gold    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.


Did you like this resource? Share it with your friends and show your love!





Responses to "DropdownList's selected text into TextBox"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Javascript ToolTip
    Previous Resource: Printing contents of controls in .Net
    Return to Resources
    Post New Resource
    Category: ASP.NET/Web Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    DropdownList's selected text into TextBox  .  

    My Profile

    Active Members
    TodayLast 7 Daysmore...


    Awards & Gifts


    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.