Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Listbox containing duplicate items - correct selection not maintained on postback?

Reply
Thread Tools

Listbox containing duplicate items - correct selection not maintained on postback?

 
 
Adam Clauss
Guest
Posts: n/a
 
      09-07-2005
I have a page containing a list box. This list may contain duplicate
items - in which the ORDER is important.
ex:
a
b
b
a

is significant as compared to:
b
a
a
b

even though the list contains the same elements. The user has buttons on
the page to reorder the list.

The problem is that, say in the first example, the bottom 'a' is selected.
Then a button is pressed that causes a postback. The re-selected item is
now the FIRST a. Likewise, if the second 'b' is selected, on postback the
FIRST b will be selected.

The following page demonstrates this:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="testListbox.WebForm1" smartNavigation="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<asp:ListBox id="ListBox1" runat="server">
<asp:ListItem Value="item1">item1</asp:ListItem>
<asp:ListItem Value="item2">item2</asp:ListItem>
<asp:ListItem Value="item1">item1</asp:ListItem>
</asp:ListBox>
</form>
</body>
</HTML>


There was no code added to the codebehind page. (I just created a simple
web app to demonstrate this).

Is there anyway to resolve this issue such that the correct element is
selected (by index rather than value)?
--
Adam Clauss



 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-07-2005
Adam,

Yes the Listbox object has a SelectedIndex property, it gets or sets the
SelectedIndex.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Adam Clauss" <> wrote in message
news:...
>I have a page containing a list box. This list may contain duplicate
>items - in which the ORDER is important.
> ex:
> a
> b
> b
> a
>
> is significant as compared to:
> b
> a
> a
> b
>
> even though the list contains the same elements. The user has buttons on
> the page to reorder the list.
>
> The problem is that, say in the first example, the bottom 'a' is selected.
> Then a button is pressed that causes a postback. The re-selected item is
> now the FIRST a. Likewise, if the second 'b' is selected, on postback the
> FIRST b will be selected.
>
> The following page demonstrates this:
>
> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
> AutoEventWireup="false" Inherits="testListbox.WebForm1"
> smartNavigation="True"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body>
> <form id="Form1" method="post" runat="server">
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
> <asp:ListBox id="ListBox1" runat="server">
> <asp:ListItem Value="item1">item1</asp:ListItem>
> <asp:ListItem Value="item2">item2</asp:ListItem>
> <asp:ListItem Value="item1">item1</asp:ListItem>
> </asp:ListBox>
> </form>
> </body>
> </HTML>
>
>
> There was no code added to the codebehind page. (I just created a simple
> web app to demonstrate this).
>
> Is there anyway to resolve this issue such that the correct element is
> selected (by index rather than value)?
> --
> Adam Clauss
>
>
>



 
Reply With Quote
 
 
 
 
Adam Clauss
Guest
Posts: n/a
 
      09-07-2005
Huh? Yes, I'm aware of that property.
The problem is I'm not setting the selection - ASP.NET is automatically.

--
Adam Clauss

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%23v3w59%...
> Adam,
>
> Yes the Listbox object has a SelectedIndex property, it gets or sets the
> SelectedIndex.
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "Adam Clauss" <> wrote in message
> news:...
>>I have a page containing a list box. This list may contain duplicate
>>items - in which the ORDER is important.
>> ex:
>> a
>> b
>> b
>> a
>>
>> is significant as compared to:
>> b
>> a
>> a
>> b
>>
>> even though the list contains the same elements. The user has buttons on
>> the page to reorder the list.
>>
>> The problem is that, say in the first example, the bottom 'a' is
>> selected. Then a button is pressed that causes a postback. The
>> re-selected item is now the FIRST a. Likewise, if the second 'b' is
>> selected, on postback the FIRST b will be selected.
>>
>> The following page demonstrates this:
>>
>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>> AutoEventWireup="false" Inherits="testListbox.WebForm1"
>> smartNavigation="True"%>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>> <HTML>
>> <HEAD>
>> <title>WebForm1</title>
>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>> <meta name="CODE_LANGUAGE" Content="C#">
>> <meta name="vs_defaultClientScript" content="JavaScript">
>> <meta name="vs_targetSchema"
>> content="http://schemas.microsoft.com/intellisense/ie5">
>> </HEAD>
>> <body>
>> <form id="Form1" method="post" runat="server">
>> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>> <asp:ListBox id="ListBox1" runat="server">
>> <asp:ListItem Value="item1">item1</asp:ListItem>
>> <asp:ListItem Value="item2">item2</asp:ListItem>
>> <asp:ListItem Value="item1">item1</asp:ListItem>
>> </asp:ListBox>
>> </form>
>> </body>
>> </HTML>
>>
>>
>> There was no code added to the codebehind page. (I just created a simple
>> web app to demonstrate this).
>>
>> Is there anyway to resolve this issue such that the correct element is
>> selected (by index rather than value)?
>> --
>> Adam Clauss
>>
>>
>>

>
>



 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-07-2005
Yes,

You'll have to set it yourself.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Adam Clauss" <> wrote in message
news:...
> Huh? Yes, I'm aware of that property.
> The problem is I'm not setting the selection - ASP.NET is automatically.
>
> --
> Adam Clauss
>
> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
> message news:%23v3w59%...
>> Adam,
>>
>> Yes the Listbox object has a SelectedIndex property, it gets or sets the
>> SelectedIndex.
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "Adam Clauss" <> wrote in message
>> news:...
>>>I have a page containing a list box. This list may contain duplicate
>>>items - in which the ORDER is important.
>>> ex:
>>> a
>>> b
>>> b
>>> a
>>>
>>> is significant as compared to:
>>> b
>>> a
>>> a
>>> b
>>>
>>> even though the list contains the same elements. The user has buttons
>>> on the page to reorder the list.
>>>
>>> The problem is that, say in the first example, the bottom 'a' is
>>> selected. Then a button is pressed that causes a postback. The
>>> re-selected item is now the FIRST a. Likewise, if the second 'b' is
>>> selected, on postback the FIRST b will be selected.
>>>
>>> The following page demonstrates this:
>>>
>>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>>> AutoEventWireup="false" Inherits="testListbox.WebForm1"
>>> smartNavigation="True"%>
>>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>>> <HTML>
>>> <HEAD>
>>> <title>WebForm1</title>
>>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>>> <meta name="CODE_LANGUAGE" Content="C#">
>>> <meta name="vs_defaultClientScript" content="JavaScript">
>>> <meta name="vs_targetSchema"
>>> content="http://schemas.microsoft.com/intellisense/ie5">
>>> </HEAD>
>>> <body>
>>> <form id="Form1" method="post" runat="server">
>>> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>>> <asp:ListBox id="ListBox1" runat="server">
>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>> <asp:ListItem Value="item2">item2</asp:ListItem>
>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>> </asp:ListBox>
>>> </form>
>>> </body>
>>> </HTML>
>>>
>>>
>>> There was no code added to the codebehind page. (I just created a
>>> simple web app to demonstrate this).
>>>
>>> Is there anyway to resolve this issue such that the correct element is
>>> selected (by index rather than value)?
>>> --
>>> Adam Clauss
>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Adam Clauss
Guest
Posts: n/a
 
      09-07-2005
In EVERY postback I do?? This page has a lot of postback's on it... that
doesn't seem very efficient.

--
Adam Clauss

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:eDE2eK$...
> Yes,
>
> You'll have to set it yourself.
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "Adam Clauss" <> wrote in message
> news:...
>> Huh? Yes, I'm aware of that property.
>> The problem is I'm not setting the selection - ASP.NET is automatically.
>>
>> --
>> Adam Clauss
>>
>> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
>> message news:%23v3w59%...
>>> Adam,
>>>
>>> Yes the Listbox object has a SelectedIndex property, it gets or sets the
>>> SelectedIndex.
>>>
>>> --
>>> Sincerely,
>>>
>>> S. Justin Gengo, MCP
>>> Web Developer / Programmer
>>>
>>> www.aboutfortunate.com
>>>
>>> "Out of chaos comes order."
>>> Nietzsche
>>> "Adam Clauss" <> wrote in message
>>> news:...
>>>>I have a page containing a list box. This list may contain duplicate
>>>>items - in which the ORDER is important.
>>>> ex:
>>>> a
>>>> b
>>>> b
>>>> a
>>>>
>>>> is significant as compared to:
>>>> b
>>>> a
>>>> a
>>>> b
>>>>
>>>> even though the list contains the same elements. The user has buttons
>>>> on the page to reorder the list.
>>>>
>>>> The problem is that, say in the first example, the bottom 'a' is
>>>> selected. Then a button is pressed that causes a postback. The
>>>> re-selected item is now the FIRST a. Likewise, if the second 'b' is
>>>> selected, on postback the FIRST b will be selected.
>>>>
>>>> The following page demonstrates this:
>>>>
>>>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>>>> AutoEventWireup="false" Inherits="testListbox.WebForm1"
>>>> smartNavigation="True"%>
>>>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>>>> <HTML>
>>>> <HEAD>
>>>> <title>WebForm1</title>
>>>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>>>> <meta name="CODE_LANGUAGE" Content="C#">
>>>> <meta name="vs_defaultClientScript" content="JavaScript">
>>>> <meta name="vs_targetSchema"
>>>> content="http://schemas.microsoft.com/intellisense/ie5">
>>>> </HEAD>
>>>> <body>
>>>> <form id="Form1" method="post" runat="server">
>>>> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>>>> <asp:ListBox id="ListBox1" runat="server">
>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>> <asp:ListItem Value="item2">item2</asp:ListItem>
>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>> </asp:ListBox>
>>>> </form>
>>>> </body>
>>>> </HTML>
>>>>
>>>>
>>>> There was no code added to the codebehind page. (I just created a
>>>> simple web app to demonstrate this).
>>>>
>>>> Is there anyway to resolve this issue such that the correct element is
>>>> selected (by index rather than value)?
>>>> --
>>>> Adam Clauss
>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-07-2005
Adam,

Maybe I'm misunderstanding what you're doing. Does the item order in the
list box change with every post back. If the list box has viewstate enabled
on it it should stay exactly the same unless you re-bind it or the user
changes the order. Every time a post-back is done where the user changes the
order you'll have to set the proper index if .Net can't do it itself. But
that certainly shouldn't be on every post back.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Adam Clauss" <> wrote in message
news:...
> In EVERY postback I do?? This page has a lot of postback's on it... that
> doesn't seem very efficient.
>
> --
> Adam Clauss
>
> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
> message news:eDE2eK$...
>> Yes,
>>
>> You'll have to set it yourself.
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "Adam Clauss" <> wrote in message
>> news:...
>>> Huh? Yes, I'm aware of that property.
>>> The problem is I'm not setting the selection - ASP.NET is automatically.
>>>
>>> --
>>> Adam Clauss
>>>
>>> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
>>> message news:%23v3w59%...
>>>> Adam,
>>>>
>>>> Yes the Listbox object has a SelectedIndex property, it gets or sets
>>>> the SelectedIndex.
>>>>
>>>> --
>>>> Sincerely,
>>>>
>>>> S. Justin Gengo, MCP
>>>> Web Developer / Programmer
>>>>
>>>> www.aboutfortunate.com
>>>>
>>>> "Out of chaos comes order."
>>>> Nietzsche
>>>> "Adam Clauss" <> wrote in message
>>>> news:...
>>>>>I have a page containing a list box. This list may contain duplicate
>>>>>items - in which the ORDER is important.
>>>>> ex:
>>>>> a
>>>>> b
>>>>> b
>>>>> a
>>>>>
>>>>> is significant as compared to:
>>>>> b
>>>>> a
>>>>> a
>>>>> b
>>>>>
>>>>> even though the list contains the same elements. The user has buttons
>>>>> on the page to reorder the list.
>>>>>
>>>>> The problem is that, say in the first example, the bottom 'a' is
>>>>> selected. Then a button is pressed that causes a postback. The
>>>>> re-selected item is now the FIRST a. Likewise, if the second 'b' is
>>>>> selected, on postback the FIRST b will be selected.
>>>>>
>>>>> The following page demonstrates this:
>>>>>
>>>>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>>>>> AutoEventWireup="false" Inherits="testListbox.WebForm1"
>>>>> smartNavigation="True"%>
>>>>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>>>>> <HTML>
>>>>> <HEAD>
>>>>> <title>WebForm1</title>
>>>>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>>>>> <meta name="CODE_LANGUAGE" Content="C#">
>>>>> <meta name="vs_defaultClientScript" content="JavaScript">
>>>>> <meta name="vs_targetSchema"
>>>>> content="http://schemas.microsoft.com/intellisense/ie5">
>>>>> </HEAD>
>>>>> <body>
>>>>> <form id="Form1" method="post" runat="server">
>>>>> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>>>>> <asp:ListBox id="ListBox1" runat="server">
>>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>>> <asp:ListItem Value="item2">item2</asp:ListItem>
>>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>>> </asp:ListBox>
>>>>> </form>
>>>>> </body>
>>>>> </HTML>
>>>>>
>>>>>
>>>>> There was no code added to the codebehind page. (I just created a
>>>>> simple web app to demonstrate this).
>>>>>
>>>>> Is there anyway to resolve this issue such that the correct element is
>>>>> selected (by index rather than value)?
>>>>> --
>>>>> Adam Clauss
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Adam Clauss
Guest
Posts: n/a
 
      09-08-2005
Again - try running the code/page I gave on the first post.
I do not have to change or reorder anything to cause this problem.

Problem in short - have a page with a button (with no event actually bound
to it), and a listbox with contents as:
a
b
b
a

Select the bottom a. Then press the button.
The first a is what shows up as selected when the page reappears.

Select the bottom b. Then press the button.
The first b is what shows up as selected when the page reappears.

--
Adam Clauss

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:u1VgFo$...
> Adam,
>
> Maybe I'm misunderstanding what you're doing. Does the item order in the
> list box change with every post back. If the list box has viewstate
> enabled on it it should stay exactly the same unless you re-bind it or the
> user changes the order. Every time a post-back is done where the user
> changes the order you'll have to set the proper index if .Net can't do it
> itself. But that certainly shouldn't be on every post back.
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "Adam Clauss" <> wrote in message
> news:...
>> In EVERY postback I do?? This page has a lot of postback's on it... that
>> doesn't seem very efficient.
>>
>> --
>> Adam Clauss
>>
>> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
>> message news:eDE2eK$...
>>> Yes,
>>>
>>> You'll have to set it yourself.
>>>
>>> --
>>> Sincerely,
>>>
>>> S. Justin Gengo, MCP
>>> Web Developer / Programmer
>>>
>>> www.aboutfortunate.com
>>>
>>> "Out of chaos comes order."
>>> Nietzsche
>>> "Adam Clauss" <> wrote in message
>>> news:...
>>>> Huh? Yes, I'm aware of that property.
>>>> The problem is I'm not setting the selection - ASP.NET is
>>>> automatically.
>>>>
>>>> --
>>>> Adam Clauss
>>>>
>>>> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
>>>> message news:%23v3w59%...
>>>>> Adam,
>>>>>
>>>>> Yes the Listbox object has a SelectedIndex property, it gets or sets
>>>>> the SelectedIndex.
>>>>>
>>>>> --
>>>>> Sincerely,
>>>>>
>>>>> S. Justin Gengo, MCP
>>>>> Web Developer / Programmer
>>>>>
>>>>> www.aboutfortunate.com
>>>>>
>>>>> "Out of chaos comes order."
>>>>> Nietzsche
>>>>> "Adam Clauss" <> wrote in message
>>>>> news:...
>>>>>>I have a page containing a list box. This list may contain duplicate
>>>>>>items - in which the ORDER is important.
>>>>>> ex:
>>>>>> a
>>>>>> b
>>>>>> b
>>>>>> a
>>>>>>
>>>>>> is significant as compared to:
>>>>>> b
>>>>>> a
>>>>>> a
>>>>>> b
>>>>>>
>>>>>> even though the list contains the same elements. The user has
>>>>>> buttons on the page to reorder the list.
>>>>>>
>>>>>> The problem is that, say in the first example, the bottom 'a' is
>>>>>> selected. Then a button is pressed that causes a postback. The
>>>>>> re-selected item is now the FIRST a. Likewise, if the second 'b' is
>>>>>> selected, on postback the FIRST b will be selected.
>>>>>>
>>>>>> The following page demonstrates this:
>>>>>>
>>>>>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>>>>>> AutoEventWireup="false" Inherits="testListbox.WebForm1"
>>>>>> smartNavigation="True"%>
>>>>>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>>>>>> <HTML>
>>>>>> <HEAD>
>>>>>> <title>WebForm1</title>
>>>>>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>>>>>> <meta name="CODE_LANGUAGE" Content="C#">
>>>>>> <meta name="vs_defaultClientScript" content="JavaScript">
>>>>>> <meta name="vs_targetSchema"
>>>>>> content="http://schemas.microsoft.com/intellisense/ie5">
>>>>>> </HEAD>
>>>>>> <body>
>>>>>> <form id="Form1" method="post" runat="server">
>>>>>> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>>>>>> <asp:ListBox id="ListBox1" runat="server">
>>>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>>>> <asp:ListItem Value="item2">item2</asp:ListItem>
>>>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>>>> </asp:ListBox>
>>>>>> </form>
>>>>>> </body>
>>>>>> </HTML>
>>>>>>
>>>>>>
>>>>>> There was no code added to the codebehind page. (I just created a
>>>>>> simple web app to demonstrate this).
>>>>>>
>>>>>> Is there anyway to resolve this issue such that the correct element
>>>>>> is selected (by index rather than value)?
>>>>>> --
>>>>>> Adam Clauss
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Damien
Guest
Posts: n/a
 
      09-08-2005
Adam Clauss wrote:
> I have a page containing a list box. This list may contain duplicate
> items - in which the ORDER is important.
> ex:
> a
> b
> b
> a
>
> is significant as compared to:
> b
> a
> a
> b
>
> even though the list contains the same elements. The user has buttons on
> the page to reorder the list.
>
> The problem is that, say in the first example, the bottom 'a' is selected.
> Then a button is pressed that causes a postback. The re-selected item is
> now the FIRST a. Likewise, if the second 'b' is selected, on postback the
> FIRST b will be selected.
>
> The following page demonstrates this:
>
> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
> Inherits="testListbox.WebForm1" smartNavigation="True"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body>
> <form id="Form1" method="post" runat="server">
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
> <asp:ListBox id="ListBox1" runat="server">
> <asp:ListItem Value="item1">item1</asp:ListItem>
> <asp:ListItem Value="item2">item2</asp:ListItem>
> <asp:ListItem Value="item1">item1</asp:ListItem>
> </asp:ListBox>
> </form>
> </body>
> </HTML>
>

The listbox needs to have distinct item values in order to distinguish
the items within it.

Try, for instance:

<asp:ListItem Value="item1_instance1">item1</asp:ListItem>
<asp:ListItem Value="item2_instance1">item2</asp:ListItem>
<asp:ListItem Value="item1_instance2">item1</asp:ListItem>

Or anything else. If you're only concerned with the textual contents of
the listbox for everything else, the values could simply be 1, 2, 3,
....

Damien

 
Reply With Quote
 
Adam Clauss
Guest
Posts: n/a
 
      09-08-2005
Ah... that did it. Yeah - only the text is significant, so I was able to
disregard the actual values (just plugged in an incrementing value).

--
Adam Clauss

"Damien" <> wrote in message
news: oups.com...
> Adam Clauss wrote:
>> I have a page containing a list box. This list may contain duplicate
>> items - in which the ORDER is important.
>> ex:
>> a
>> b
>> b
>> a
>>
>> is significant as compared to:
>> b
>> a
>> a
>> b
>>
>> even though the list contains the same elements. The user has buttons on
>> the page to reorder the list.
>>
>> The problem is that, say in the first example, the bottom 'a' is
>> selected.
>> Then a button is pressed that causes a postback. The re-selected item is
>> now the FIRST a. Likewise, if the second 'b' is selected, on postback
>> the
>> FIRST b will be selected.
>>
>> The following page demonstrates this:
>>
>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>> AutoEventWireup="false"
>> Inherits="testListbox.WebForm1" smartNavigation="True"%>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>> <HTML>
>> <HEAD>
>> <title>WebForm1</title>
>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>> <meta name="CODE_LANGUAGE" Content="C#">
>> <meta name="vs_defaultClientScript" content="JavaScript">
>> <meta name="vs_targetSchema"
>> content="http://schemas.microsoft.com/intellisense/ie5">
>> </HEAD>
>> <body>
>> <form id="Form1" method="post" runat="server">
>> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>> <asp:ListBox id="ListBox1" runat="server">
>> <asp:ListItem Value="item1">item1</asp:ListItem>
>> <asp:ListItem Value="item2">item2</asp:ListItem>
>> <asp:ListItem Value="item1">item1</asp:ListItem>
>> </asp:ListBox>
>> </form>
>> </body>
>> </HTML>
>>

> The listbox needs to have distinct item values in order to distinguish
> the items within it.
>
> Try, for instance:
>
> <asp:ListItem Value="item1_instance1">item1</asp:ListItem>
> <asp:ListItem Value="item2_instance1">item2</asp:ListItem>
> <asp:ListItem Value="item1_instance2">item1</asp:ListItem>
>
> Or anything else. If you're only concerned with the textual contents of
> the listbox for everything else, the values could simply be 1, 2, 3,
> ...
>
> Damien
>



 
Reply With Quote
 
Adam Clauss
Guest
Posts: n/a
 
      09-08-2005
OK - maybe partially my fault for giving a bad example in my first post.
Damien hit the problem.

What the first example should have said was that:
a
b
b
a **selected

is significant as to:
a **selected
b
b
a

Order itself is important too, but that wasn't the actual problem.
Apologies for being unclear and making things confusing

--
Adam Clauss

"Adam Clauss" <> wrote in message
news:...
> Again - try running the code/page I gave on the first post.
> I do not have to change or reorder anything to cause this problem.
>
> Problem in short - have a page with a button (with no event actually bound
> to it), and a listbox with contents as:
> a
> b
> b
> a
>
> Select the bottom a. Then press the button.
> The first a is what shows up as selected when the page reappears.
>
> Select the bottom b. Then press the button.
> The first b is what shows up as selected when the page reappears.
>
> --
> Adam Clauss
>
> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
> message news:u1VgFo$...
>> Adam,
>>
>> Maybe I'm misunderstanding what you're doing. Does the item order in the
>> list box change with every post back. If the list box has viewstate
>> enabled on it it should stay exactly the same unless you re-bind it or
>> the user changes the order. Every time a post-back is done where the user
>> changes the order you'll have to set the proper index if .Net can't do it
>> itself. But that certainly shouldn't be on every post back.
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "Adam Clauss" <> wrote in message
>> news:...
>>> In EVERY postback I do?? This page has a lot of postback's on it...
>>> that doesn't seem very efficient.
>>>
>>> --
>>> Adam Clauss
>>>
>>> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
>>> message news:eDE2eK$...
>>>> Yes,
>>>>
>>>> You'll have to set it yourself.
>>>>
>>>> --
>>>> Sincerely,
>>>>
>>>> S. Justin Gengo, MCP
>>>> Web Developer / Programmer
>>>>
>>>> www.aboutfortunate.com
>>>>
>>>> "Out of chaos comes order."
>>>> Nietzsche
>>>> "Adam Clauss" <> wrote in message
>>>> news:...
>>>>> Huh? Yes, I'm aware of that property.
>>>>> The problem is I'm not setting the selection - ASP.NET is
>>>>> automatically.
>>>>>
>>>>> --
>>>>> Adam Clauss
>>>>>
>>>>> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote
>>>>> in message news:%23v3w59%...
>>>>>> Adam,
>>>>>>
>>>>>> Yes the Listbox object has a SelectedIndex property, it gets or sets
>>>>>> the SelectedIndex.
>>>>>>
>>>>>> --
>>>>>> Sincerely,
>>>>>>
>>>>>> S. Justin Gengo, MCP
>>>>>> Web Developer / Programmer
>>>>>>
>>>>>> www.aboutfortunate.com
>>>>>>
>>>>>> "Out of chaos comes order."
>>>>>> Nietzsche
>>>>>> "Adam Clauss" <> wrote in message
>>>>>> news:...
>>>>>>>I have a page containing a list box. This list may contain duplicate
>>>>>>>items - in which the ORDER is important.
>>>>>>> ex:
>>>>>>> a
>>>>>>> b
>>>>>>> b
>>>>>>> a
>>>>>>>
>>>>>>> is significant as compared to:
>>>>>>> b
>>>>>>> a
>>>>>>> a
>>>>>>> b
>>>>>>>
>>>>>>> even though the list contains the same elements. The user has
>>>>>>> buttons on the page to reorder the list.
>>>>>>>
>>>>>>> The problem is that, say in the first example, the bottom 'a' is
>>>>>>> selected. Then a button is pressed that causes a postback. The
>>>>>>> re-selected item is now the FIRST a. Likewise, if the second 'b' is
>>>>>>> selected, on postback the FIRST b will be selected.
>>>>>>>
>>>>>>> The following page demonstrates this:
>>>>>>>
>>>>>>> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>>>>>>> AutoEventWireup="false" Inherits="testListbox.WebForm1"
>>>>>>> smartNavigation="True"%>
>>>>>>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>>>>>>> <HTML>
>>>>>>> <HEAD>
>>>>>>> <title>WebForm1</title>
>>>>>>> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>>>>>>> <meta name="CODE_LANGUAGE" Content="C#">
>>>>>>> <meta name="vs_defaultClientScript" content="JavaScript">
>>>>>>> <meta name="vs_targetSchema"
>>>>>>> content="http://schemas.microsoft.com/intellisense/ie5">
>>>>>>> </HEAD>
>>>>>>> <body>
>>>>>>> <form id="Form1" method="post" runat="server">
>>>>>>> <asp:Button id="Button1" runat="server"
>>>>>>> Text="Button"></asp:Button>
>>>>>>> <asp:ListBox id="ListBox1" runat="server">
>>>>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>>>>> <asp:ListItem Value="item2">item2</asp:ListItem>
>>>>>>> <asp:ListItem Value="item1">item1</asp:ListItem>
>>>>>>> </asp:ListBox>
>>>>>>> </form>
>>>>>>> </body>
>>>>>>> </HTML>
>>>>>>>
>>>>>>>
>>>>>>> There was no code added to the codebehind page. (I just created a
>>>>>>> simple web app to demonstrate this).
>>>>>>>
>>>>>>> Is there anyway to resolve this issue such that the correct element
>>>>>>> is selected (by index rather than value)?
>>>>>>> --
>>>>>>> Adam Clauss
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
Listbox selection to populate another listbox? Chris Kettenbach ASP .Net 3 06-16-2005 09:19 PM
ViewState Not maintained for ListBox updated through Client vilas h via .NET 247 ASP .Net 1 06-05-2004 08:20 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
listbox control removing duplicate items Ramakrishna ASP .Net Web Controls 0 11-04-2003 01:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57