[Last Call] Learn how to a build a cloud-first strategyRegister Now


Error at conversion from datarow to string using a dataset

Posted on 2007-10-11
Medium Priority
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

Sammy Ageil earned 2000 total points
ID: 20059492
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

ID: 20059522
Thanks! That worked!

Easy when you know!


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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