Still having a problem with using a DataList

A

Aussie Rules

Hi,

I am still having a problem using a datalist control using VB.net

This is my code......

In the HTML page I have

<asp:DataList ID="DataList1" runat="server">

</asp:DataList>


In the codebehind file (code below) I get an error saying that NAME
datalist1 is not declared........

What am I doing wrong here????

Codebehind contents.....

Try

Dim SQLServerConnection As SqlConnection
Dim SqlConnectionCls As New clsSQL
Dim SqlDataAdapter As New SqlDataAdapter
Dim ds As New Data.DataSet

SQLServerConnection = SqlConnectionCls.Connect

Dim SqlCommand As New SqlCommand

With SqlCommand

.CommandType = Data.CommandType.StoredProcedure
.Connection = SQLServerConnection
.CommandTimeout = 15
.CommandText = "sproc_GetBannerAdvertDetails"

End With

SqlDataAdapter.SelectCommand = SqlCommand
SqlDataAdapter.Fill(ds, "data")
DataList1.DataSource = ds.Tables("data")
DataList1.DataBind()


Catch ex As Exception

End Try
 
G

Guest

Hi,

I am still having a problem using a datalist control using VB.net

This is my code......

In the HTML page I have

<asp:DataList ID="DataList1" runat="server">

</asp:DataList>

In the codebehind file (code below) I get an error saying that NAME
datalist1 is not declared........

What am I doing wrong here????

Codebehind contents.....

Try

Dim SQLServerConnection As SqlConnection
Dim SqlConnectionCls As New clsSQL
Dim SqlDataAdapter As New SqlDataAdapter
Dim ds As New Data.DataSet

SQLServerConnection = SqlConnectionCls.Connect

Dim SqlCommand As New SqlCommand

With SqlCommand

.CommandType = Data.CommandType.StoredProcedure
.Connection = SQLServerConnection
.CommandTimeout = 15
.CommandText = "sproc_GetBannerAdvertDetails"

End With

SqlDataAdapter.SelectCommand = SqlCommand
SqlDataAdapter.Fill(ds, "data")
DataList1.DataSource = ds.Tables("data")
DataList1.DataBind()

Catch ex As Exception

End Try

This probably due to some problem with the declaration of the
control.

What version of ASP.NET you're running?

VS.NET should create a declaration for each control on the form. A
place where that declaration is added depends on the version and a
type of project. For example, in a Web Application Project in ASP.NET
2.0 each web form has a special *.designer.vb file, that contains the
control declarations within a partial class. In ASP.NET 2.0 Web Site
Project the control declarations generated dynamically. In ASP.NET
1.0 /1.1 declarations were included in the code-behind class.

Try to delete the control from the page and add it again.
 
G

Guest

I have sometimes found that crazy problems like this go away when you remove
the control from the page and add it again.

You are using .net 2 right?
 
G

Guest

I think the issue here may be that you don't have anything inside your
Datalist to bind to, just an empty set of DataList tags. DataList needs to
have templates that define the HTML Elements that your data will be databound
to.
The best place to start is the ASP.NET quickstarts. Also, you have an empty
Catch block which buys you nothing other than to swallow any exceptions,
which is very bad coding form.
Peter
 
W

Walter Wang [MSFT]

Hi Aussie,

Since I didn't see you come back after community members replied, I'm
wondering if you think this issue has been solved or not. If not, please
feel free to let us know. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Aussie Rules

Hi,

Sorry was away for a few days.

Yes this has resolved my problems.

Thanks all
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top