Data Binding to a Drop Down List?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 14
Reputation: vbgaya is an unknown quantity at this point 
Solved Threads: 0
vbgaya vbgaya is offline Offline
Newbie Poster

Data Binding to a Drop Down List?

 
0
  #1
Aug 14th, 2006
I want to fill a drop down list with some data in a data source.
I defined a page level array and redim it in Page_Load.
I get an error saying
"Object reference not set to an instance of an object"
The error occurs at the statement,
Page.DataBind()
Below is the code (I omitted unnesary HTML codes
for the presentation)
Can you please tell me how to correct this?
Thank you
vbgaya.
===============
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
dim strService(5) as string
sub Page_Load(obj as object, e as EventArgs)
dim objConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/scms/database/scms.mdb"))
objConn.Open()
dim objCmd as new OleDbDataAdapter("select * from services", objConn)
Dim cb as New OleDbCommandBuilder(objCmd)
dim ds as DataSet = new DataSet()
objCmd.Fill(ds, "services")
dim n as integer
n = ds.Tables("services").Rows.Count
redim strService(n)
dim i as integer
for i = 0 to n-1
strService(i) = ds.Tables("services").Rows(i)("ServceName").ToString
next
objConn.Close()
Page.DataBind()
end sub
</script>
<html>
<head>
<title>Maintain Categories</title>
<link rel="stylesheet" type="text/css" href="support-files/main.css">
</head>
<body>
<form runat="server">
<asp:dropdownlist ID="lbService" DataSource='<%# strService %>' runat="server" />
</form>
</body>
</html>
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 19
Reputation: postmaster is an unknown quantity at this point 
Solved Threads: 1
postmaster postmaster is offline Offline
Newbie Poster

Re: Data Binding to a Drop Down List?

 
0
  #2
Aug 15th, 2006
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC