Using datatables for datasource

2 posts, 0 answers
  1. Mac
    Mac avatar
    7 posts
    Member since:
    Jul 2008

    Posted 11 Sep 2008 Link to this post

    I'm trying to extract information from a dbase into the rotator. This is the code i have so far:

    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Drawing
    Imports Telerik.Web.UI
    Imports System.Collections.Generic
    Partial Class fullview
        Inherits System.Web.UI.Page
        Private Structure fileInfo
            Public Url As String
            Public Image As String
              End Structure

        Private Property imagesArray() As List(Of fileInfo)
                Return DirectCast(ViewState("imagesArray"), List(Of fileInfo))
            End Get
            Set(ByVal value As List(Of fileInfo))
                ViewState("imagesArray") = value
            End Set
        End Property
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim rotatorData As New DataTable()
            Dim conn As Data.SqlClient.SqlConnection
            Dim cmd As Data.SqlClient.SqlCommand
            Dim reader As Data.SqlClient.SqlDataReader
            conn = New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings.Item(1).ToString)

            Dim gal, photo, urli As String
            urli = Request.QueryString("galleryName")
            'temp = urli.Substring(urli.IndexOf("=") + 1, (urli.IndexOf("&")) - (urli.IndexOf("=") + 1))
            gal = urli.Replace("%20", " ")
            urli = Request.QueryString("photo")
            photo = urli.Replace("%20", " ")
            Response.Write(urli & gal & photo)
            cmd = New Data.SqlClient.SqlCommand("select * from Gallery where GalleryName='" & gal & "' and UserID=" & Session("uid"), conn)
            imagesArray = New List(Of fileInfo)()

            reader = cmd.ExecuteReader

            If (reader.HasRows) Then

                While (reader.Read())

                    Dim fInfo As New fileInfo()
                    fInfo.Url = "<a href=" & Chr(34) & "javascript:ajaxpage('fullview.aspx?galleryname=" & gal & "&photo=" & Trim(reader("PictureURL").ToString) & "','contentarea')" & Chr(34) & ">"
                    fInfo.Image = "'images/users/" & Session("uid") & "/" & gal & "/Thumbnails/" & Trim(reader("PictureURL").ToString) & "'"

                End While
            End If

        End Sub
        Private Sub RebindRotator()
            Dim rotatorData As New DataTable()
            For Each tempInfo As fileInfo In imagesArray
                rotatorData.Rows.Add(New String() {tempInfo.Url, tempInfo.Image})

            RadRotator1.DataSource = rotatorData()
        End Sub

    End Class

    and the aspx:

     <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
            <telerik:RadRotator ID="RadRotator1" runat="server">
          <a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>"><img src="<%# DataBinder.Eval(Container.DataItem, "Image") %>"</a>
            <br />

    The error i get is:

    Server Error in '/profiles' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be indexed because it has no default property.

    Source Error:

    Line 65:         Next
    Line 66:
    Line 67: RadRotator1.DataSource = rotatorData()
    Line 68: RadRotator1.DataBind()
    Line 69: End Sub

    I was hoping that since i gleaned this tactic from one of your examples, you might be able to help me with that, since i'm not having much luck on the net.
    Thanks in advance.
  2. Georgi Tunev
    Georgi Tunev avatar
    7207 posts

    Posted 15 Sep 2008 Link to this post

    Hi Mac,

    Without being able to examine your project locally, I cannot be of much help, but looking at your code, I notice that  in the table, the name of the column is "Url", while in the rotator's template you are using "URL" - this might be the reason for the problem.

    If you still experience difficulties with this scenario, please open a support ticket and send us a small sample project where it can be reproduced - we will check it and do our best to help. Just make sure that the project can be run locally and attach it to the support thread.

    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top