Crew .NET |
|
Hier is de hulp...
De naam en voornaam staan in de ListBox, vanaf je verandert van naam wordt het bijhorende emailadres in het tekstvak weergegeven...
Default2.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<!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>.: .NET met titjes :.</title>
</head>
<body>
<form id="form_een" runat="server">
<div>
<asp:Label ID="lbl_een" runat="server" Text="Voornamen:" />
<br />
<asp:ListBox ID="box_een" runat="server" OnSelectedIndexChanged="keuze_Click" AutoPostBack="True" />
<br /><br />
<asp:Label ID="lbl_twee" runat="server" Text="Bijbehorend emailadres" AssociatedControlID="email_vak" />
<br />
<asp:TextBox ID="email_vak" runat="server" />
</div>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <!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>.: .NET met titjes :.</title> </head> <body> <form id="form_een" runat="server"> <div> <asp:Label ID="lbl_een" runat="server" Text="Voornamen:" /> <br /> <asp:ListBox ID="box_een" runat="server" OnSelectedIndexChanged="keuze_Click" AutoPostBack="True" /> <br /><br /> <asp:Label ID="lbl_twee" runat="server" Text="Bijbehorend emailadres" AssociatedControlID="email_vak" /> <br /> <asp:TextBox ID="email_vak" runat="server" /> </div> </form> </body> </html>
Default2.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Dim verbinding As SqlConnection
Dim commando As SqlCommand
Dim reader As SqlDataReader
Dim item As ListItem
Dim query, naam, naam_db As String
Protected Sub Page_Load(ByVal sender As Object, ByVal E As EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Protected Sub keuze_Click(ByVal sender As Object, ByVal E As EventArgs)
verbinding = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=H:\ASP.NET\DataGrid Tekstvak\App_Data\Database.mdf; Integrated Security=True; User Instance=True")
naam = box_een.SelectedValue.ToString()
query = "SELECT email FROM leden WHERE voornaam = '" & naam & "' "
commando = New SqlCommand(query, verbinding)
Try
verbinding.Open()
reader = commando.ExecuteReader()
While reader.Read()
naam_db = reader.GetString(0)
End While
reader.Close()
Catch ex As Exception
Response.Write(ex.Message)
Finally
verbinding.Close()
End Try
email_vak.Text = naam_db
End Sub
Protected Sub BindData()
verbinding = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=H:\ASP.NET\DataGrid Tekstvak\App_Data\Database.mdf; Integrated Security=True; User Instance=True")
query = "SELECT voornaam, achternaam FROM leden"
commando = New SqlCommand(query, verbinding)
Try
verbinding.Open()
reader = commando.ExecuteReader()
While reader.Read()
item = New ListItem
item.Text = reader.GetString(0) + " " + reader.GetString(1)
item.Value = reader.GetString(0)
box_een.Items.Add(item)
End While
reader.Close()
Catch ex As Exception
Response.Write(ex.Message)
Finally
verbinding.Close()
End Try
End Sub
End Class
Partial Class Default2 Dim verbinding As SqlConnection Dim commando As SqlCommand Dim reader As SqlDataReader Dim item As ListItem Dim query, naam, naam_db As String Protected Sub Page_Load(ByVal sender As Object, ByVal E As EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindData() Protected Sub keuze_Click(ByVal sender As Object, ByVal E As EventArgs) verbinding = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=H:\ASP.NET\DataGrid Tekstvak\App_Data\Database.mdf; Integrated Security=True; User Instance=True") naam = box_een.SelectedValue.ToString() query = "SELECT email FROM leden WHERE voornaam = '" & naam & "' " commando = New SqlCommand(query, verbinding) Try verbinding.Open() reader = commando.ExecuteReader() While reader.Read() naam_db = reader.GetString(0) reader.Close() Catch ex As Exception Response.Write(ex.Message) Finally verbinding.Close() email_vak.Text = naam_db Protected Sub BindData() verbinding = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=H:\ASP.NET\DataGrid Tekstvak\App_Data\Database.mdf; Integrated Security=True; User Instance=True") query = "SELECT voornaam, achternaam FROM leden" commando = New SqlCommand(query, verbinding) Try verbinding.Open() reader = commando.ExecuteReader() While reader.Read() item = New ListItem item.Text = reader.GetString(0) + " " + reader.GetString(1) item.Value = reader.GetString(0) box_een.Items.Add(item) reader.Close() Catch ex As Exception Response.Write(ex.Message) Finally verbinding.Close()
Edit aan de crew:
- Nogmaals sorry voor de lange code, maar aangezien dit de enige oplossing is kan het geen kwaad denk ik.
- Toch handig die kleurtjes
|