Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Urgent! WebFrom ListBox

0 views
Skip to first unread message

Aytac Oral

unread,
Apr 5, 2002, 4:27:51 AM4/5/02
to
I've 2 listbox objects on a webform, first one is filled with
some data generated form a dataset, and the second one is
blank. I want to add the items of the first listbox to the
second whenever user selects an item from the first.
It's something like that;

private void lbBranch_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Label1.Text = "You selected " +
lbBranch.SelectedIndex.ToString();

for (int i=0; i < lbSelectedBranch.Items.Count;
i++)
{
if (lbSelectedBranch.Items[i] != lbBranch.Items
[lbBranch.SelectedIndex])
{
lbSelectedBranch.Items.Add
(lbBranch.Items[lbBranch.SelectedIndex]);
}
}
}

But Label1.Text always shows a value of -1 alhtough
lbBranch's (the first listbox) AutoPost property is True
Any idea?


Felix Wu(MS)

unread,
Apr 9, 2002, 5:36:12 AM4/9/02
to
Hi Aytac,

It seems that the selected value is lost, so that the defaul value -1 is returned.

How did you fill the lbBranch listbox? You need to use IsPostBack property to prevent the listbox from being filled each time when postback occurs. Something like this:

void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
lbBranch.DataSource=.....
lbBranch.DataBind();
}
}

Also, make sure the AutoPostBack of the first listbox is set to true;

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Content-Class: urn:content-classes:message
>From: "Aytac Oral" <ay...@kocbank.com.tr>
>Sender: "Aytac Oral" <ay...@kocbank.com.tr>
>Subject: Urgent! WebFrom ListBox
>Date: Fri, 5 Apr 2002 01:27:51 -0800
>Lines: 29
>Message-ID: <1e4e01c1dc84$282bafb0$95e62ecf@tkmsftngxs02>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
>Thread-Index: AcHchCgr+i5JDXkZTBGCfOObkvWvCA==
>Newsgroups: microsoft.public.dotnet.languages.csharp
>NNTP-Posting-Host: tkmsftngxs02 127.0.0.1
>Path: cpmsftngxa08!cpmsftngxa07!tkmsftngxs01!tkmsftngxs02
>Xref: cpmsftngxa08 microsoft.public.dotnet.languages.csharp:50872
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Aytac Oral

unread,
Apr 9, 2002, 7:39:20 AM4/9/02
to
Thnx. I've already solved the problem as you indicated

Sincerly,

>.
>

0 new messages