Hi
I have below code in Aspx page but i want to display image thru Repeater RowDataBound.
Code
' />Thanks
Hi
I have below code in Aspx page but i want to display image thru Repeater RowDataBound.
' />Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ramco RamcoRank #462 · 5.4K reputationPosted Jun 17, 2023, 12:48 AM EDT
Hi Vishal
I have to get image through ItemDataBound
Thanks
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 16, 2023, 5:22 AM EDT
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Access the current data item DataRowView dataItem = (DataRowView)e.Item.DataItem; // Find the Image control within the Repeater item Image img = (Image)e.Item.FindControl("imgThumb"); // Set the source attribute of the Image control to the ThumbImage value from the data item img.Attributes["src"] = dataItem["ThumbImage"].ToString(); } }Deepak RawatRank #646 · 3.7K reputationPosted Jun 16, 2023, 6:29 AM EDT
Add the Repeater control to your ASPX page and set its DataSource property to the desired data source.
In the code-behind file (e.g., .aspx.cs), handle the RowDataBound event of the Repeater control. This event is triggered for each item in the Repeater.
Inside the RowDataBound event handler, access the current item's data and find the Image control within the Repeater's ItemTemplate.
Set the Image control's source (src) attribute to the appropriate value using the data from the current item.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Bind the data source to the Repeater control myRepeater.DataSource = YourDataSource; myRepeater.DataBind(); } } protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Access the current data item var dataItem = e.Item.DataItem as YourDataType; // Find the Image control within the Repeater's ItemTemplate var myImage = e.Item.FindControl("myImage") as System.Web.UI.WebControls.Image; // Set the source (src) attribute of the Image control myImage.ImageUrl = dataItem.ThumbImage; } }Ramco RamcoRank #462 · 5.4K reputationPosted Jun 16, 2023, 8:18 AM EDT
Hi
I have belwo code but it is giving error - Unable to cast object of type LMS.DAL_View_BookDeliveryDetail to type System.Data.DataRowView
DataRowView dataItem = (DataRowView)e.Item.DataItem; BALBooks bALBooks = new BALBooks(); BookDetail objBook = bALBooks.GetBookList(Convert.ToInt32(hdfBookId.Value)); if (objBook != null) { img.Attributes["src"] = dataItem["ThumbImage"].ToString(); }Thanks
Vishal JoshiRank #377 · 6.7K reputationPosted Jun 16, 2023, 8:19 AM EDT
Hello Ramco,
Please try the below code to bind the image in a repeater control.
Thanks