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
On Jun 5, 7:30 pm, "Aussie Rules" <AussieRu
@nospam.nospam> wrote:
> 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.
-----------------------------------------------Reply-----------------------------------------------
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?
-----------------------------------------------Reply-----------------------------------------------
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
--
Site:
http://www.eggheadcafe.com UnBlog:
http://petesbloggerama.blogspot.com Short urls & more:
http://ittyurl.net
"Aussie Rules" wrote:
> 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