Rj Sunny Rj Sunny - 1 year ago 82
ASP.NET (C#) Question

Set div data-src url from server side in asp.net

I want to know is there any way to assign url to data-src in a div in HTML5 from server side as I fetch images from database in asp.net? Like there are 2

with attribute
in the given code. Now i want to assign those images from server side as images fetching from the database.

<div data-src="eventcss/images/slide.jpg">
<div class="caption fadeIn">
<div class="price" >
<span>10 am</span>
<a href="#">See Details</a>
<div id="checkdiv" runat="server">
<div class="caption fadeIn">
<div class="price">
<span>2 pm</span>
<a href="#">See Details</a>

I try to find the solution on google. But nothing relevant material is found.
It will be great help to me if any one guide me. Thanks

Answer Source

You could create a couple of properties in the code behind > set their values > and finally call them from the design with to populate the data-src attribute.

Code behind:

public string Div1 { get; set; }
public string Div2 { get; set; }

protected void Page_Load(object sender, EventArgs e)
    Div1 = "eventcss/images/slide.jpg";
    Div2 = "eventcss/images/slide2.jpg";


<div id="div1" data-src='<%: Div1 %>'>
<div id="div2" data-src='<%: Div2 %>'>