Populating datalist control

J

Jerry Higgins

I have a datalist control on a web page and I am trying
to populate it through the page_load event.

The name of the control on the web page is "MyList".

I had code behind a button click to populate it and that
worked. Now that I've moved the code to the page_load
event it is not working. I suspect that "MyList" on the
page doesn't know about "MyList" in the page_load code
but I don't know how to connect the two. Any help would
be appreciated.

Here is the code


Dim DS As DataSet
Dim MyConnection As SqlConnection

Dim MyCommand As SqlDataAdapter
Dim MyList As DataList

MyConnection = New SqlConnection
("server=x2;database=Orders;Trusted_Connection=yes")
MyCommand = New SqlDataAdapter("select
ReferenceNO, Loc from Request", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Request")

MyList = New DataList
MyList.DataSource = DS.Tables
("Request").DefaultView

MyList.DataBind()
 
S

Scott Mitchell [MVP]

Dim DS As DataSet
Dim MyConnection As SqlConnection

Dim MyCommand As SqlDataAdapter
Dim MyList As DataList

Why do you have Dim MyList as DataList in your Page_Load event handler?
Your code-behind class shold have had a:

Protected MyList as DataList

automatically added when you dropped the DataList onto the VS.NET designer.

The rest of your code looks kosher.

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,121
Messages
2,570,712
Members
47,283
Latest member
hopkins1988

Latest Threads

Top