944,175 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 24837
  • ASP.NET RSS
Aug 14th, 2006
0

Data Binding to a Drop Down List?

Expand Post »
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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgaya is offline Offline
14 posts
since Aug 2006
Aug 15th, 2006
0

Re: Data Binding to a Drop Down List?

Reputation Points: 10
Solved Threads: 1
Newbie Poster
postmaster is offline Offline
19 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Schema information
Next Thread in ASP.NET Forum Timeline: Getting Current Row Values in the DataGrid control





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC