Answered by:
fill div in asp.net from table in database

Question
-
User-910565666 posted
I want to fill div in asp.net from table in database . my table name is events. I tried to use <%#Eval("") %> but it didn't work.
this is my asp code
<section class="mainContent full-width clearfix coursesSection" Runat="Server"> <div class="container" Runat="Server"> <div class="row" Runat="Server"> <div class="col-sm-6 col-xs-12 block" Runat="Server"> <div class="media eventContent bg-color-1" Runat="Server"> <% EccoSchoolEntities db = new EccoSchoolEntities(); %> <a class="media-left" Runat="Server" href="single-event-left-sidebar.html"> <img Runat="Server" class="media-object" src="/zewail/assets/img/home/event/event-1.jpg" alt="Image"> <span Runat="Server" class="sticker-round"><%#Eval("db.events.start_date") %> <br><%#Eval("db.events.duration") %></span> </a> <div class="media-body" Runat="Server"> <h3 Runat="Server" class="media-heading"><a href="single-event-left-sidebar.html"><%#Eval("db.events.title") %></a></h3> <ul Runat="Server" class="list-unstyled"> <li><i Runat="Server" class="fa fa-calendar-o" aria-hidden="true"></i><%#Eval("db.events.content") %></li> <li><i Runat="Server" class="fa fa-clock-o" aria-hidden="true"></i><%#Eval("db.events.price") %></li> </ul> <p><%#Eval("db.events.location") %> </p> <ul Runat="Server" class="list-inline btn-yellow"> <li><a href="single-event-left-sidebar.html" Runat="Server" class="btn btn-primary"></a></li> </ul> </div> </div> </div> </div> </div> </section>
please help
Sunday, November 25, 2018 2:38 PM
Answers
-
User61956409 posted
Hi Zainab Mostafa hashem,
Welcome to ASP.NET forums.
Firstly, if you'd like to retrieve records of event from your database table, and display data on web form via data binding, as others mentioned, you can try to use data-bound control.
Besides, if you just want to dynamically display data that stored in database on web page, you can also use jQuery AJAX to call web method to retrieve records and dynamically populate/generate html based on returned data on client side.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, November 26, 2018 2:44 AM
All replies
-
User475983607 posted
It seems that you added runat="server" to HTML controls and expect binding to magically function.
I recommend that you go through a few Getting Started tutorials related to data bound controls and working with data in Web Forms. If you need very customized HTML then look into the repeater.
https://msdn.microsoft.com/en-us/library/x8f2zez5.aspx?f=255&MSPPError=-2147217396
Sunday, November 25, 2018 3:55 PM -
User-471420332 posted
search in Google "how to fill gridview using asp.net" you will get your result.Sunday, November 25, 2018 4:18 PM -
User61956409 posted
Hi Zainab Mostafa hashem,
Welcome to ASP.NET forums.
Firstly, if you'd like to retrieve records of event from your database table, and display data on web form via data binding, as others mentioned, you can try to use data-bound control.
Besides, if you just want to dynamically display data that stored in database on web page, you can also use jQuery AJAX to call web method to retrieve records and dynamically populate/generate html based on returned data on client side.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, November 26, 2018 2:44 AM -
User-910565666 posted
excuse me i'm beginner , can you help me at my code what is missing in the code to be right
Monday, November 26, 2018 10:24 AM -
User-471420332 posted
Can you post your .cs Code?
Monday, November 26, 2018 10:51 AM -
User-910565666 posted
cs code is empty now
here it is
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class zewail_events : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
Monday, November 26, 2018 10:56 AM -
User-471420332 posted
Without coding how data fill ?
Please use below example.
Monday, November 26, 2018 2:24 PM -
User475983607 posted
excuse me i'm beginner , can you help me at my code what is missing in the code to be right
I recommend going through the Getting Started Tutorials on this site.
Monday, November 26, 2018 2:36 PM