When interviewing new users, some project managers always like to ask: "How do you usually help when binding front-end page data ?".
In fact, this problem is not a problem. It is not a problem because it is very simple. It is a problem because most new people do not know it, and some people who work do not know it, generally, the project framework of a big company has its own encapsulated controls. You just need to drag them and use them.
The following is a simple example of front-end data binding without server controls. I hope this will be helpful to those who do not know much about it.
1. Check the background cs file first.
1 using System. Data; // namespace required by DataTable
2 protected DataTable dt; // create a protected DataTable
3 BLL. BContent bllContent = new BLL. BContent (); // don't worry, as long as you know that this is an operation class called to read data.
4 protected void Page_Load (object sender, EventArgs e)
5 {
6 dt = bllContent. GetTable ("News", "id! = 8 "," id "); // fill the dt with the structure and data. [BllContent. GetTable () does not care about this method, as long as you know that it returns the DataTable data type]
7}
The background Code actually reads data and binds it to a DataTable. Pay attention to the key word of DataTable.
2. Data Binding on the front-end page
1 <div>
2 <ul class = "items">
3 <% foreach (System. Data. DataRow drPro in dt. Rows) {%>
4 <li> <a href = 'show? Id = <% = drPro ["id"]. toString () %> '> <% = drPro ["name"]. toString () %> </a> </li>
5 <% }%>
6 </ul>
7 </div>
I saw whether the front-end binding is speechless. Yes, as long as people who have used the Repeater control have done similar binding, sometimes it is just a window.
Here, we will remind you that, when binding data pagination is involved, such as the effect:
You need to write a cs paging class.
In addition, you can also use the above method when encapsulating your own controls. This article ends, hoping to help you.
From Feng Hu