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?
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
Sincerly,
>.
>