View Single Post
  #2 (permalink)  
Old July 19th, 2003, 11:24 PM
melvik melvik is offline
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

I hope this sample will help u!
plz set the connection string for ur own Server!

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">
  Sub Page_Load( s As Object, e As EventArgs )
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    If Not isPostBack Then
      ' Get List of Categories From Database
      myConnection = New SQLConnection( "Server=Localhost;uid=sa;pwd=secret;Database=North wind" )
      myCommand = New SqlCommand( "Select CategoryName From Categories", myConnection )
      myConnection.Open()
      category.DataSource = myCommand.ExecuteReader()
      category.DataTextField = "CategoryName"
      category.DataBind()
      myConnection.Close()
    End If
  End Sub

  Sub pickCat( s As Object, e As EventArgs )
    currentCat.Text = category.SelectedItem.Text
  End Sub
</Script>


<html>
<head><title>Categories</title></head>
<body>

<form Runat="Server">

Please select a category:
<br>
<asp:DropDownList
  id="category"
  Runat="Server" />

<asp:button
  Text="Select!"
  onClick="pickCat"
  Runat="Server" />

<p>

Current Category:
<asp:Label
  id="currentCat"
  Runat="Server" />

</form>


</body>
</html>


Always:),
Hovik Melkomian.
Reply With Quote