what's wrong with this code?

Discussion in 'ASP .Net Datagrid Control' started by Chris, Feb 5, 2007.

  1. Chris

    Chris Guest

    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>
     
    Chris, Feb 5, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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], Feb 5, 2007
    #2
    1. Advertising

  3. Chris

    Chris Guest

    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 [MVP]" <some guy without an email address> schreef in bericht
    news:...
    > 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" <> wrote in message
    > news:...
    >> 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>
    >>
    >>

    >
    >
     
    Chris, Feb 6, 2007
    #3
  4. Chris

    Chris Guest

    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 [MVP]" <some guy without an email address> schreef in bericht
    news:...
    > 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" <> wrote in message
    > news:...
    >> 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>
    >>
    >>

    >
    >
     
    Chris, Feb 6, 2007
    #4
  5. 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" <qffg> wrote in message
    news:...
    >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 [MVP]" <some guy without an email address> schreef in
    > bericht news:...
    >> 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" <> wrote in message
    >> news:...
    >>> 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], Feb 11, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    2,217
    Ralf Hildebrandt
    Sep 10, 2003
  2. willem oosthuizen

    What is wrong with the following code?

    willem oosthuizen, Oct 10, 2003, in forum: VHDL
    Replies:
    9
    Views:
    1,308
  3. Matthew
    Replies:
    7
    Views:
    739
    Priscilla Walmsley
    Jan 7, 2005
  4. David. E. Goble
    Replies:
    9
    Views:
    492
    David. E. Goble
    Feb 2, 2005
  5. kiran
    Replies:
    12
    Views:
    1,153
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page