Hi everybody...
I have this problem...every time I select an item from a ListBox, the ListBox automatically selects the first item of the list...but this problem only happens when I execute this code:
But When I execute the following code, the listboxes doesn't reset to their first item every time I select another item
I don't know where the problem is... I hope you can help me
regards
jorge
I have this problem...every time I select an item from a ListBox, the ListBox automatically selects the first item of the list...but this problem only happens when I execute this code:
VB.NET:
Partial Class _Default
Inherits System.Web.UI.Page
Dim ListBoxArray(3) As ListBox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ListBoxArray(1) = ListBox1
ListBoxArray(2) = ListBox2
ListBoxArray(3) = ListBox3
If Not IsPostBack Then
Dim i As Integer
For i = 1 To 4
'this listbox doesnt reset
ListBoxArray(1).Items.Add(i)
'This two listboxes reset, but why?
ListBoxArray(2).Items.Add(0)
ListBoxArray(3).Items.Add(0)
Next
End If
End Sub
End Class
HTML:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"></asp:ListBox>
<asp:ListBox ID="ListBox2" runat="server" AutoPostBack="True"></asp:ListBox>
<asp:ListBox ID="ListBox3" runat="server" AutoPostBack="True"></asp:ListBox>
</div>
</form>
</body>
</html>
But When I execute the following code, the listboxes doesn't reset to their first item every time I select another item
VB.NET:
Partial Class _Default
Inherits System.Web.UI.Page
Dim ListBoxArray(3) As ListBox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ListBoxArray(1) = ListBox1
ListBoxArray(2) = ListBox2
ListBoxArray(3) = ListBox3
If Not IsPostBack Then
Dim i As Integer
For i = 1 To 4
'everything ok
ListBoxArray(1).Items.Add(i)
ListBoxArray(2).Items.Add(i)
ListBoxArray(3).Items.Add(i)
Next
End If
End Sub
End Class
HTML:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"></asp:ListBox>
<asp:ListBox ID="ListBox2" runat="server" AutoPostBack="True"></asp:ListBox>
<asp:ListBox ID="ListBox3" runat="server" AutoPostBack="True"></asp:ListBox>
</div>
</form>
</body>
</html>
I don't know where the problem is... I hope you can help me
regards
jorge