...

ASP:Repeater help

shaoen01
02-11-2006, 08:19 AM
Currently, i am using a asp:repeater to bind my images from database to a imagebutton. For example, i have 2 images in the database. Therefore, the repeater should have generate 2 imagebuttons for me. And each imagebutton is suppose to show 2 different images.

Somehow both imagebuttons are displaying the same images, which always happens to be the 2nd image. Before the itemdatabound, i already databind it to an arraylist. The imgRetrieve.aspx is used to retrieve/display image for me based on the id passed in. Any help is greatly appreciated.


<asp:repeater id="repImages" runat="server" OnItemDataBound="repImages_ItemDataBound">
<ItemTemplate>
<asp:ImageButton runat="server" ID="imgItem" CssClass="removeBorder" onmouseover="this.className='applyBorder'"
onmouseout="this.className='removeBorder'" Width="100" Height="100" OnClick="imgItem_Click" />
<br>
</ItemTemplate>
</asp:repeater>



Protected Sub repImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repImages.ItemDataBound

Dim Item As RepeaterItem = CType(e.Item, RepeaterItem)
Dim MyImage As New ImageButton
MyImage = CType(Item.FindControl("imgItem"), ImageButton)
dim index as integer=0
for index=0 to imgArrList.count-1
MyImage.ImageUrl = "..\imgRetrieve.aspx?id=" & imgArrList.item(index).staffid
end next

comradekev
03-02-2006, 04:33 PM
I think you might be overthinking it a bit. When using a repeater, all you should have to do is to bind it to a dataset of the items from your DB.
For example (emphasis on the ImageUrl):
<asp:repeater id="repImages" runat="server" >
<ItemTemplate>
<asp:ImageButton runat="server" ID="imgItem" CssClass="removeBorder"
onmouseover="this.className='applyBorder'"
onmouseout="this.className='removeBorder'"
Width="100" Height="100" OnClick="imgItem_Click"
ImageUrl='<%# container.dataitem("rowname") %>'
</asp:ImageButton>
<br>
</ItemTemplate>
</asp:repeater>


Then within your code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'instantiate DB routines
Dim DB As New SQL_Calls

'Call DB routines to READ table, returning Dataset of all rows
repImages.DataSource = DB.ReadTbl

'Bind the Dataset to the Repeater
repImages.DataBind()
End If
End Sub

Then within the SQL_Calls.ReadTbl you define your SQL. I think what's happening with your code is that you have your repeater bound outside the code that you included. For EACH row that it gets, it runs through your repImages_ItemDataBound. This would cause each row to loop through the FOR loop imgArrList.count times and the last image would be attached to EACH row.

Does that make sense?
Kev



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum