Postback problem?

J

Jerome

The selected item is always lost when I submit the page ... why??

Any help is greatly appreciated!

Here's my code:
**************

<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data.Sqlclient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Dim strConString as String = ConfigurationSettings.AppSettings("conString")

Sub Page_Load

If Not IsPostBack then

Dim conRubriques as SQLConnection
Dim cmdSelect as SQLCommand
Dim dtrRubriques as SqlDataReader

conRubriques= New SqlConnection(strConString)
conRubriques.Open()
cmdSelect= New SqlCommand("SELECT dbo.tVisites.IDRubrique,
dbo.tVisites.VisiteOrdre, dbo.tVisites.VisiteNom, [NomRubrique] + ': ' +
[VisiteNom] AS Visite, dbo.tVisites.Internet FROM dbo.tVisites INNER
JOIN dbo.tRubriques ON dbo.tVisites.IDRubrique =
dbo.tRubriques.IDRubrique ORDER BY dbo.tVisites.VisiteOrdre", conRubriques)
dtrRubriques = cmdSelect.ExecuteReader()
listbox1.DataSource= dtrRubriques
listbox1.DataValueField = "IDRubrique"
listbox1.DataTextField = "Visite"
listbox1.DataBind()
dtrRubriques.Close()
conRubriques.Close()

End If

End Sub

Sub MergeActiv(s as object, e as eventargs)

textbox1.text=listbox1.SelectedItem.Text

End sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
<p>
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="single"
Rows="5"></asp:ListBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Save"
OnClick="MergeActiv" /></p>
<p>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"
Columns="200" />
</p>
</form>
</body>
</html>
 
J

Jerome

The selected item is not really lost, in fact the page always defaults
to the first item in the list and then copies it to my textbox! Even if
I had the third one selected for example.

any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top