tags:

views:

256

answers:

1

hi guys, I have following code in page load

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            GetDetails()
            PopulateRepeater()
        End If
    End Sub

Sub PopulateRepeater()
        Dim dt As DataTable = GetDetails()
        Dim dtDoc As DataTable = objdoc.GetDocDetails(Session("RegID"))
        If dtDoc.Rows.Count > 0 Then
            Dim strUserName As String = dt.Rows(0)("Name")
            Dim files As IList(Of FileInfo) = New List(Of FileInfo)()
            Dim filters As String = "*.jpg;*.png;*.gif"
            For Each filter As String In filters.Split(";"c)
                Dim fit As FileInfo() = New DirectoryInfo(Me.Server.MapPath("../SiteImages/" & strUserName & "/" & Session("RegID") & "/")).GetFiles(filter)
                For Each fi As FileInfo In fit
                    files.Add(fi)
                Next
            Next
            strPath = Server.MapPath("../SiteImages/" & strUserName & "/" & Session("RegID") & "/")
            Me.Repeater1.DataSource = files
            Me.Repeater1.DataBind()
        End If

        End Sub

I have following code in itemdatabound

Dim ThViewr As Bright.WebControls.ThumbViewer = DirectCast(e.Item.FindControl("Th1"), Bright.WebControls.ThumbViewer)
        Dim dtUser As DataTable = GetDetails()
        Dim dtDoc As DataTable = objdoc.GetDocDetails(Session("RegID"))
        Dim strUserName As String = dtUser.Rows(0)("Name")
        If dtDoc.Rows.Count > 0 Then
            For i As Integer = 0 To dtDoc.Rows.Count - 1
                Dim ImagePath As String = "../SiteImages/" & strUserName & "/" & Session("RegID") & "/" + dtDoc.Rows(i)("ImageName")
                ThViewr.ImageUrl = ImagePath
            Next

        End If

My aspx contains

<div style="clear:both;">
                <asp:Repeater ID="Repeater1" runat="server" >
                    <ItemTemplate>
                        <span style="padding:2px 10px 2px 10px">

                            <bri:ThumbViewer Id="Th1"  runat="server" Height="100px" Width="100px"/>
                        </span>
                    </ItemTemplate>
                </asp:Repeater>
            </div>

If the imagePath ="../SiteImages/Ram/PR/First.jpg" Means the folder PR aontains exactly 3 images namely First.jpg,Second.jpg and Third.jpg.

Now with above code three images are coming but Third.jpg is repeating 3 times.First.jpg and Second.jpg is not coming.Can anybody help to resolve this.

+1  A: 

The ItemDataBound event is raised once for every object in the bound list, so it will be fired three times in your case; once for each file. You should not loop over your data table, but rather grab the current item from the event args.

Update: looking closer at the code I find it somewhat confusing. You bind a list of FileInfo objects to the repeater, but fetch data from a DataTable when the items are bound. I am guessing that you want to show the files found, and I think that the following code in ItemDataBound will do that for you:

Dim ThViewr As Bright.WebControls.ThumbViewer = DirectCast(e.Item.FindControl("Th1"), Bright.WebControls.ThumbViewer)
Dim dtUser As DataTable = GetDetails()
Dim strUserName As String = dtUser.Rows(0)("Name")
Dim ImagePath As String = "../SiteImages/" & strUserName & "/" & Session("RegID") & "/" + DirectCast(e.Item.DataItem, FileInfo).Name
ThViewr.ImageUrl = ImagePath
Fredrik Mörk
Can u show 1 eg:
It worked.Thanks a lot.