Solved

Why the row value is nothing?

Posted on 2008-10-01
4
235 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

14 Experts available now in Live!

Get 1:1 Help Now