Solved

Why the row value is nothing?

Posted on 2008-10-01
4
244 Views
Last Modified: 2012-05-05
Hi, I'm trying to retrieve the repeater's row at databound time but the row returned nothing:
       Dim row As DataRowView = TryCast(e.Item.DataItem, DataRowView)

Below is the entire code:
Private Sub rptList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptList.ItemDataBound
        Dim imgIcon As Image = CType(e.Item.FindControl("imgIcon"), Image)
        Dim row As DataRowView = TryCast(e.Item.DataItem, DataRowView)
 
End Sub

Open in new window

0
Comment
Question by:Abdu_Allah
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Snarf0001
ID: 22613474
Can you show the code for your databinding?  Are you sure it's a DataRowView being returned?
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22613515
Here is the code of binding:

Dim directory2 As DirectoryInfo = New DirectoryInfo(strPath)
Try
rptList.DataSource = directory2.GetFiles()
rptList.DataBind()
Catch ex As System.UnauthorizedAccessException
Response.Write(" Access Denied.")
Catch ex As System.IO.IOException
Response.Write(" Unknown error: " + ex.Message)
Finally
directory2 = Nothing
End Try
0
 
LVL 22

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 22613556
Okay, thats exactly the problem.
You'll only get a DataRowView if you're binding with a datatable / dataview.

since you're binding with DirectoryInfo.GetFiles(), which returns an array of FileInfo objects, that's what you need to cast to.
Private Sub rptList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptList.ItemDataBound
        Dim imgIcon As Image = CType(e.Item.FindControl("imgIcon"), Image)
        Dim info As FileInfo = TryCast(e.Item.DataItem, FileInfo)
 
End Sub

Open in new window

0
 
LVL 20

Expert Comment

by:informaniac
ID: 22613602
TRY THIS

       
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then

Dim imgIcon As Image = CType(e.Item.FindControl("imgIcon"), Image)
        Dim row As DataRowView = TryCast(e.Item.DataItem, DataRowView)

End If
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in JQuery 5 54
ASP.net Fit image buttons according to size of the screen 2 22
ASP.NET MVC 2 32
Function after success of Jquery/AJAX action 9 18
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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