Error at conversion from datarow to string using a dataset

Posted on 2007-10-11
Last Modified: 2008-01-09

I get this error when using a dataset to bind my data to a datalist control programmatically:
Conversion from type 'DataRowView' to type 'String' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Conversion from type 'DataRowView' to type 'String' is not valid.

Source Error:

Line 42:        
Line 43:         ' Get the row data
Line 44:         Dim imageId As String = e.Item.DataItem
Line 45:
Line 46:

My code is like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cImage As New imagesDL
        dlImages.DataSource = cImage.GetImagesAllSystem
    End Sub

Protected Sub dlImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlImages.ItemDataBound
        ' Get the row data
        Dim imageId As String = e.Item.DataItem

        ' Find the row controls
        Dim myILoad As Radactive.WebControls.ILoad.ILoad = e.Item.FindControl("ILoad1")
        Dim myLabel As Label = e.Item.FindControl("Label1")
        Dim myImageButton As ImageButton = e.Item.FindControl("ImageButton1")

        If Radactive.WebControls.ILoad.WebImage.FileExists(Server.MapPath("Uploads/images"), imageId) Then
            ' Load data inside the controls
            myILoad.Value = Radactive.WebControls.ILoad.WebImage.Load(Server.MapPath("Uploads/images"), imageId)
            myLabel.Text = "Original file name:" + myILoad.Value.SourceImageClientFileName
            myImageButton.ImageUrl = myILoad.Value.IconImage.FileUrl
            myImageButton.OnClientClick = "showILoadPreview('" + myILoad.ClientID + "'); return false;"
        End If
    End Sub

Grafeful fro help with what's missing!


Question by:peternordberg
    LVL 27

    Accepted Solution

    You have to tell it which Item and cast it to a string
    Dim imageId As String = CType(e.Item.DataItem,System.Data.DataRowView)("THE BOUND ITEM NAME").ToString()

    Author Comment

    Thanks! That worked!

    Easy when you know!


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now