Click to See Complete Forum and Search --> : help using databind on DropDownList


flynny1st
February 21st, 2008, 10:59 AM
hi all i have the following aspx file


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ODBC" %>
<!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 id="Head1" runat="server">
<title>Add New Stock.</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1">
<tr>
<td>
Select Manufacturer
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>


and i default.aspx.vb is


Imports System.Data
Imports System.Data.Odbc

Partial Class _Default

Inherits System.Web.UI.Page
Private Const ConnStr As String = "DRIVER={MySQL ODBC 3.51 Driver};Server=*;Database=*;User=*;Password=*;OPTION=3"

Sub Page_Load(Source As Object, E As EventArgs)
if Not Page.IsPostBack Then
Dim con As OdbcConnection = New OdbcConnection(ConnStr)
Dim cmd As OdbcCommand = New OdbcCommand("SELECT * FROM suppliers", con)

con.Open()
DropDownList1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
DropDownList1.DataBind()

end if
End Sub

End Class


it runs ok however the dropdownlist appears empty as though theres nothing in the table. I do however know that there is as i have retrived entries using clasic asp. any ideas?