Solved

Why the row value is nothing?

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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