The code in this article is C #
I have seen many CMS systems, and they are incredibly powerful and admirable. However, if there are gains or losses, the functions may not be good. After all, they cannot be used.
Furthermore, after all, it is developed by others, which limits development.
I was so itchy that I wanted to write a. NET-based CMS.
No more nonsense.
Let's talk about binding data first.
There are multiple data binding methods.
① Use server controls
Note: Drag controls are the biggest reason for the Master's contempt for. net. There are many drawbacks, resulting in a lot of junk code, which has a great impact on the layout of the web page and cannot make beautiful pages.
Therefore, it is not described here.
② Direct loop output html
Example:
<Div>
<Ul>
<%
String strWhere = ""; // Condition
Int currentPage = 1; // current page
If (Request. QueryString ["PageNum"]! = Null)
{
If (v. IsInteger (Request. QueryString ["PageNum"]. ToString () = "") // you can determine whether the value is a number.
{
CurrentPage = int. Parse (Request. QueryString ["PageNum"]. ToString ());
}
}
Int showCounts = 15; // The number of rows displayed on the page is www.2cto.com.
String strOrder = "order by [CreateDateTime] DESC"; // sorting rule
List <News> list_News = newsDao. GetAllNews (currentPage, showCounts, strWhere, strOrder); // obtain News data
Pager p = newsDao. GetAllNewsPager (currentPage, showCounts, strWhere); // obtain paging data
%>
<% Foreach (News n in list_News) %>
<% {%>
<Li> <span> <% = n. CreateDateTime %> </span> <a href = "Detail. aspx? NID = <% = n. NID %> "> <% = n. NewsTitle %> </a> </li>
<% }%>
</Ul>
</Div>
<Div>
<Span class = "pager"> <% = Method. PagerInfo ("current", p) %> </span> <! -- Page number -->
</Div>
The above is a simple example. You may write differently, but the principles are similar.
After encapsulation, the following result is obtained:
<Div>
<Ul>
<% TblName = "News"; Filed = "NewsID, Title, Time"; Num = 15; Sort = "[Time] DESC"; Page = true; %>
<% = Aspx (@"
<Li> <span> {2} </span> <a href = 'detail. aspx? NID = {0} '> {1} </a> </li>
") %>
</Ul>
</Div>
<Div>
<Span class = "pager"> <% = AspxP ("current") %> </span> <! -- Page number -->
</Div>
See if it is much simpler. In addition, you can use the custom "Aspx" function to cover all lists and fields. Paging is implemented through "AspxP.
And more flexible. TblName indicates the table name, Filed indicates the field, Num indicates the number of items displayed on the Page, Sort indicates the sorting method, and Page indicates whether to display pages.
Some other parameters are not listed in the following sections.
Is it like those CMS.
The middle is pure HTML, and it looks comfortable.
If you can write this statement without reporting an error, you can refer to my previous log, which contains an introduction.
Now, let's write it here. Next, I will introduce its principles.
The following knowledge is limited. If you are not clear about the introduction, please forgive me and leave a message if you have any questions.
Please be brave in making bricks !!!
From 19 shore