Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 10th, 2008, 04:25 AM
Authorized User
Join Date: Nov 2007
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can I set TextBox value from asp.net Listbox,

How can I set TextBox value from asp.net Listbox, because I popuplate asp.net Listbox through java script..
I tried it by calling the java script function onChange(and onSelectedIndexChange) event of list box, but event is not calling java script function

from here..

following is my code--

<div id="helptypediv" style="visibility: hidden; z-index:1">
                            <asp:ListBox ID="lstShowHistory" SelectionMode="Single" runat="server" Width="200px" Height="300px"


function setTextBoxValue(e)
            //var strListBoxName = document.getElementById('lstShowHistory');
            document.getElementById('txtUrlLink').value = e ; //strListBoxName.options[strListBoxName.selectedIndex].text ;

//;options[document.getElementById('lstShowHistory').selected Index].text;

the list box is popuplate on mouse over event on the text box...

txtUrlLink.Attributes.Add("onfocus", "ShowList();");

function ShowList()
   document.getElementById('helptypediv').style.visib ility='visible';return false;

function getCookie()
        var strListBox = document.getElementById('lstShowHistory');
        var ls1= document.cookie.split("=");
        if (ls1.length >1)
            var ls2 = ls1[1].split("|");
            var count = ls2.length;
            var strLink = "";
            var optionItem;

            //Clear the previous options from the list
            for(var lstCount = strListBox.options.length-1; lstCount>-1; lstCount--)
                strListBox.options[lstCount] = null;
            if(count >= 2 )
                for(var x = count-1; x>=0; x--)
                        var ls3=ls2[x];//[x].split("|");
                        strLink+= ls3;
                        optionItem = new Option(ls3, ls3, false, false);
                        strListBox.options[strListBox.length] = optionItem;

Old March 10th, 2008, 06:11 AM
Authorized User
Join Date: Nov 2007
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts

g is my code--
I have resolved my problem..

following is code..
in CS file i added this line ..
lstShowHistory.Attributes.Add("onchange", "ShowText();");

and by javascript I set the value of textbox, but it works only on by selecting item from mouse.
How can I select value from the listbox by arrow key of keyboard?? Have you any idea...
function ShowText()
    var txtMessage =

document.getElementById('lstShowHistory').options[document.getElementById('lstShowHistory').selected Index].text;//GetComboText(document.g

    document.getElementById('txtUrlLink').value = txtMessage;
    document.getElementById('helptypediv').style.visib ility='hidden';return false;

Similar Threads
Thread Thread Starter Forum Replies Last Post
SOS!How to realize multi-column asp.net ListBox? xewei VS.NET 2002/2003 2 June 3rd, 2007 09:24 PM
how to add scroll bars in asp.net listbox control DARSIN General .NET 3 January 26th, 2006 11:39 PM
Listbox/textbox johnjohn Classic ASP Basics 4 December 11th, 2004 12:14 AM
bag in vb.net,set enable for textBox q8z Beginning VB 6 0 October 21st, 2004 04:08 AM
Listbox to textbox Freddyfred Access VBA 2 May 10th, 2004 10:37 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.