Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why the row value is nothing?

Posted on 2008-10-01
4
Medium Priority
?
278 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 23

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 23

Accepted Solution

by:
Snarf0001 earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
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. …

876 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