what's wrong with this code?

C

Chris

Hi,

I want to limit the amount of data shown in a page coming from a database.
Everything works except that I get the error:
"Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource' to
type 'System.Collections.IEnumerable'"
on line: PageDataSource.DataSource = SqlDataSource2

Thanks for help
Chris


code-behind:
-----------
Imports System.Data
Imports System.Data.OleDb

Partial Class Item
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PageDSource As New PagedDataSource()
PageDSource.DataSource = SqlDataSource2
PageDSource.AllowPaging = True
PageDSource.PageSize = 6
End Sub
End Class


aspx file:
---------
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:prod %>"
SelectCommand="SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
<SelectParameters>
<asp:QueryStringParameter Name="CId" DefaultValue="1"
QueryStringField="ite" />
</SelectParameters>
</asp:SqlDataSource>
 
A

Alvin Bruney [MVP]

C

Chris

Hi thanks for replying, but your file is very big and i'm a little bit
confused.
Do i have to define a datareader or dataset in the code-behind and use it as
source of the PagedDataSource?
In that case, i have to redine the sql statement and select parameter
defines in the aspx file, i guess?
Thanks again


Alvin Bruney said:
The pageddatesource needs to be bound to an object of the inumerable
interface - it says so in the compiler error. Here is some code that you
can follow.
http://www.google.com/codesearch?hl...h33/Code/App_Code/BaseWebParts/GridView.cs#a0

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

Chris said:
Hi,

I want to limit the amount of data shown in a page coming from a
database.
Everything works except that I get the error:
"Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource'
to
type 'System.Collections.IEnumerable'"
on line: PageDataSource.DataSource = SqlDataSource2

Thanks for help
Chris


code-behind:
-----------
Imports System.Data
Imports System.Data.OleDb

Partial Class Item
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PageDSource As New PagedDataSource()
PageDSource.DataSource = SqlDataSource2
PageDSource.AllowPaging = True
PageDSource.PageSize = 6
End Sub
End Class


aspx file:
---------
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:prod %>"
SelectCommand="SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
<SelectParameters>
<asp:QueryStringParameter Name="CId" DefaultValue="1"
QueryStringField="ite" />
</SelectParameters>
</asp:SqlDataSource>
 
C

Chris

I tried this now, but same error:

Dim PageDataSource As New PagedDataSource()
Dim d As SqlDataAdapter
Dim ds As DataSet
Dim sql As String
Dim sConnectionString As String
sConnectionString = System....

sql = "select ..."
d = New SqlDataAdapter(sql, sConnectionString)
ds = New DataSet()
d.Fill(ds)
PageDataSource.DataSource = ds
PageDataSource.AllowPaging = True
PageDataSource.PageSize = 4

DataList1.DataSource = PageDataSource 'datalist is defined in aspx file
DataList1.DataBind()

I definitively miss something, i'm afraid of ...


Alvin Bruney said:
The pageddatesource needs to be bound to an object of the inumerable
interface - it says so in the compiler error. Here is some code that you
can follow.
http://www.google.com/codesearch?hl...h33/Code/App_Code/BaseWebParts/GridView.cs#a0

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

Chris said:
Hi,

I want to limit the amount of data shown in a page coming from a
database.
Everything works except that I get the error:
"Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource'
to
type 'System.Collections.IEnumerable'"
on line: PageDataSource.DataSource = SqlDataSource2

Thanks for help
Chris


code-behind:
-----------
Imports System.Data
Imports System.Data.OleDb

Partial Class Item
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PageDSource As New PagedDataSource()
PageDSource.DataSource = SqlDataSource2
PageDSource.AllowPaging = True
PageDSource.PageSize = 6
End Sub
End Class


aspx file:
---------
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:prod %>"
SelectCommand="SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
<SelectParameters>
<asp:QueryStringParameter Name="CId" DefaultValue="1"
QueryStringField="ite" />
</SelectParameters>
</asp:SqlDataSource>
 
A

Alvin Bruney [MVP]

Read the link i sent you again, search for .datasource, you will see it
declared as an ienumerable variable. Mirror that concept in your code. On
the larger issue of why exactly you are using that type of control, you may
want to explain a bit - without knowing your design goals, i have trouble
understanding why you can't simply use a gridview object.
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


Chris said:
I tried this now, but same error:

Dim PageDataSource As New PagedDataSource()
Dim d As SqlDataAdapter
Dim ds As DataSet
Dim sql As String
Dim sConnectionString As String
sConnectionString = System....

sql = "select ..."
d = New SqlDataAdapter(sql, sConnectionString)
ds = New DataSet()
d.Fill(ds)
PageDataSource.DataSource = ds
PageDataSource.AllowPaging = True
PageDataSource.PageSize = 4

DataList1.DataSource = PageDataSource 'datalist is defined in aspx file
DataList1.DataBind()

I definitively miss something, i'm afraid of ...


Alvin Bruney said:
The pageddatesource needs to be bound to an object of the inumerable
interface - it says so in the compiler error. Here is some code that you
can follow.
http://www.google.com/codesearch?hl...h33/Code/App_Code/BaseWebParts/GridView.cs#a0

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

Chris said:
Hi,

I want to limit the amount of data shown in a page coming from a
database.
Everything works except that I get the error:
"Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource'
to
type 'System.Collections.IEnumerable'"
on line: PageDataSource.DataSource = SqlDataSource2

Thanks for help
Chris


code-behind:
-----------
Imports System.Data
Imports System.Data.OleDb

Partial Class Item
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PageDSource As New PagedDataSource()
PageDSource.DataSource = SqlDataSource2
PageDSource.AllowPaging = True
PageDSource.PageSize = 6
End Sub
End Class


aspx file:
---------
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:prod %>"
SelectCommand="SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
<SelectParameters>
<asp:QueryStringParameter Name="CId" DefaultValue="1"
QueryStringField="ite" />
</SelectParameters>
</asp:SqlDataSource>
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top