Bind data to a non-Server Control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.