Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking 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 Basics 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 August 18th, 2006, 04:56 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikram_bendre
Default listbox control items count shows 0.

Hi experts,
  I am working on a screen where in it has a typical 2 listboxes & 2 buttons(add/remove), so when these buttons are clicked the items have to move from one listbox to another. its all working fine with javascript.
but the issue is, I am not able to get the items of the 2nd listbox in the codebehind. I tried with html & asp.net listbox controls. I even tried to access the listbox using Request.Form["ControlName"] - which gives a null value.

I am fed up with the javascript & asp.net issues... :D
Help out plz..

Vikram
 
Old August 18th, 2006, 12:24 PM
Authorized User
 
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shivanshub
Default

Hello I have this solution but in dektop application(with C#>net) But u can use same Code(by cut copy) in code file try it out . if u need code pls mail me. at [email protected]
if it will not work i will change it for ASP for u.

I am not like every body else.
 
Old August 18th, 2006, 11:05 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Issue you are having is you are changing the values on client side but these values do not exist on the server side. There is no server side reference in the aspx file for the contents you are switching. This will have to be done on server side. Of course this will require a postback which adds a flicker and ruins the dynamicness of the page hehe. Basically the button will have to be an asp button and the code behind will have to contain the code that switches the properties. If you want to have this be dynamic, you will have to do AJAX. For an easy to use free addon I suggest Atlas being Microsoft made. Makes AJAX alot easier and since you are playing with java now you will really like the client side script changes. :)


 
Old August 23rd, 2006, 01:00 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikram_bendre
Default

Hi all, the problem is solved. thanks a lot for trying. Hi shivanshu, I had sent a mail to u, but sadly u did not reply. And solution to the problem in windows and web are totally different.
Quick209, There is no need to use AJAX/ATLAS (once I tried to implement ATLAS, it seems too complicated...). Here is the solutions I found out...
-------------------------------------------
1. First of all copy/paste this javascript function

<script language="javascript">

    function selectListBoxAll()

    {

        var Sellistbox = document.getElementById("ControlName");

        for( len = 0; len < Sellistbox.options.length; len++ )

        {

            Sellistbox.options[len].selected = true;

        }

        document.getElementById("HiddenButton_ControlName" ).click();

     }

</script>





2. u should have a html button run at server(which is hidden). And one more html button which will execute the javascript function.

<div style="display:none">

                            <input type="button" id="HidBut" value="" runat="server"

                                causesvalidation="False" onserverclick="btnUpdate_Click" />

                        </div>

                        <input type="button" id="Update" value= "Update" onclick="selectListBoxAll()" />

3. u can access the contents of the second listbox with this code…

 lblMessage.Text = Request["ControlName"];


This code will return all the selected listitem values of the 2nd listbox (, separated).

Then u can split the string and use the values…

if u dont understand any part of it, u can mail me at.. [email protected]


Vikram
 
Old August 23rd, 2006, 06:12 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Looking at your code. You are using java to select the boxes but then calling a button via java to initiate a postback which has server code to handle the selected text? Since you are doing postback, you can eliminate the jscript and just write the server side code to take everything in the list box and move it. I suggested AJAX to eliminate postback page flickers so it looks more dynamic.
you can access the count in a listbox serverside by:
listbox.items.count() I believe and with that you can use a for statement to get your items from your listboxes:

string[] myitems = new string[Listbox.Items.Count];
for(int 1=0; Listbox.Items.Count > i; i++)
{
     myitems[i] = listbox.items[i].Value;
}

That will give you what is inside a list box as an array.

Don't know if you were having issues getting the data from the listbox on the server side. This should cut down your client code.
Yeah, Atlas takes some getting used to as it is onoy used to enrich your site, AJAX is more of a pain though as I done both hehe.

 
Old August 24th, 2006, 08:37 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikram_bendre
Default

Hey,
   My requirement was to move items from 1 list box to 2nd at client side and save the items of 2nd listbox.

so, when the items to a listbox(2nd) are bound at client side, the server side code does not understand it, and hence
Listbox.Items.Count will always give 0. u can not loop through the 2nd listbox.

but if I do the movement of items from 1st listbox to 2nd listbox at server side, the user will feel the pain. hence this solution... :)

Vikram





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting all listbox items Lucy_H85 C# 2005 2 December 1st, 2009 05:36 AM
WinForms ListBox with user control items vik C# 3 November 27th, 2008 10:44 AM
Count the same items stasnikov Access 2 January 15th, 2007 06:20 AM
Count the same items stasnikov Access VBA 1 January 12th, 2007 12:27 PM
Max of listbox control items Snowingnow Beginning VB 6 1 November 22nd, 2004 02:05 PM





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