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

div
with attribute
data-src
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">
<h2>Cricket</h2>
<div class="price" >
FROM
<span>10 am</span>
</div>
<a href="#">See Details</a>
</div>
</div>
<div id="checkdiv" runat="server">
<div class="caption fadeIn">
<h2>Football</h2>
<div class="price">
FROM
<span>2 pm</span>
</div>
<a href="#">See Details</a>
</div>
</div>


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";
}

.ASPX:

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

Output:

Output