Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / February 2007

Tip: Looking for answers? Try searching our database.

what's wrong with this code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris - 05 Feb 2007 22:18 GMT
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>
Alvin Bruney [MVP] - 05 Feb 2007 23:40 GMT
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=en&q=+new+PagedDataSource()%3B+show:VsAXU5o_
YNc:ibPMvVa8Myw:4b-erpyux6E&sa=N&cd=5&ct=rc&cs_p=http://media.wiley.com/product_
ancillary/07/04717935/DOWNLOAD/793507%2520ch33.zip&cs_f=793507+ch33/Code/App_Cod
e/BaseWebParts/GridView.cs#a0


Signature

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

> Hi,
>
[quoted text clipped - 36 lines]
>        </SelectParameters>
>    </asp:SqlDataSource>
Chris - 06 Feb 2007 18:52 GMT
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

> 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
[quoted text clipped - 42 lines]
>>        </SelectParameters>
>>    </asp:SqlDataSource>
Chris - 06 Feb 2007 20:14 GMT
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 ...

> 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
[quoted text clipped - 42 lines]
>>        </SelectParameters>
>>    </asp:SqlDataSource>
Alvin Bruney [MVP] - 11 Feb 2007 14:27 GMT
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.
Signature

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

>I tried this now, but same error:
>
[quoted text clipped - 64 lines]
>>>        </SelectParameters>
>>>    </asp:SqlDataSource>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.