J
Jerome
I keep getting this error!? It seems like the code can't find the control?
Here's my code:
---------------------------
<%@ Page Language="VB" ContentType="text/html" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<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 NomRubrique,
dbo.tVisites.VisiteOrdre", conRubriques)
dtrRubriques = cmdSelect.ExecuteReader()
lstVisite1.DataSource= dtrRubriques
lstVisite1.DataValueField = "VisiteNom"
lstVisite1.DataTextField = "Visite"
lstVisite1.DataBind()
dtrRubriques.Close()
conRubriques.Close()
End If
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
dim cnOVS as sqlconnection
dim strInsert as string
dim cmdInsert as sqlcommand
dim strVis as string
cnOVS= new sqlconnection(strConString)
strInsert= "Insert tInscrip (Visites) values (@Visites)"
cmdInsert=new sqlcommand (strInsert, cnOVS)
strVis = lstVisite1.SelectedItem.Value
cmdInsert.parameters.add("@Visites", strVis)
cnOVS.open()
cmdInsert.ExecuteNonQuery()
cnOVS.close()
End Sub
</script>
<html>
<body>
<p>Online Umeldung fir Visiten vum Service Educatif</p>
<form name="form1" runat="server">
<p>1. Visit: <asp:ListBox ID="lstVisite1" Runat="server" />
<asp:Button ID="Button1" Text="enregistrer" runat="server"
OnClick="button1_Click" /></p>
</form>
</body>
</html>
--------------------------------------------
And this line causes the error: strVis = lstVisite1.SelectedItem.Value
Anyone have any idea what the problem could be??
Thanks a lot!
Here's my code:
---------------------------
<%@ Page Language="VB" ContentType="text/html" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<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 NomRubrique,
dbo.tVisites.VisiteOrdre", conRubriques)
dtrRubriques = cmdSelect.ExecuteReader()
lstVisite1.DataSource= dtrRubriques
lstVisite1.DataValueField = "VisiteNom"
lstVisite1.DataTextField = "Visite"
lstVisite1.DataBind()
dtrRubriques.Close()
conRubriques.Close()
End If
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
dim cnOVS as sqlconnection
dim strInsert as string
dim cmdInsert as sqlcommand
dim strVis as string
cnOVS= new sqlconnection(strConString)
strInsert= "Insert tInscrip (Visites) values (@Visites)"
cmdInsert=new sqlcommand (strInsert, cnOVS)
strVis = lstVisite1.SelectedItem.Value
cmdInsert.parameters.add("@Visites", strVis)
cnOVS.open()
cmdInsert.ExecuteNonQuery()
cnOVS.close()
End Sub
</script>
<html>
<body>
<p>Online Umeldung fir Visiten vum Service Educatif</p>
<form name="form1" runat="server">
<p>1. Visit: <asp:ListBox ID="lstVisite1" Runat="server" />
<asp:Button ID="Button1" Text="enregistrer" runat="server"
OnClick="button1_Click" /></p>
</form>
</body>
</html>
--------------------------------------------
And this line causes the error: strVis = lstVisite1.SelectedItem.Value
Anyone have any idea what the problem could be??
Thanks a lot!