A
Adam Clauss
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)?
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)?