asp.net baidutemplate template engine usage examples (with source code)

Source: Internet
Author: User

1, new project, asp.net empty Web application

Add Data,js,styles,templates folder, add Baidutemplate.js,jquery.js,bootstrap.css

2, add List.js script, the code is as follows

Vardata = {
"List": [
{
"Col1": "Line 1",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 2",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 3",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 4",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 5",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 6",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 7",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
},
{
"Col1": "Line 8",
"Col2": "Data 2",
"Col3": "Data 3",
"Col4": "Data 6",
"COL5": "Data 5",
"COL6": "Data 6"
}
]
};
Vartemplate = "templates/list.html";
$.ajax ({
Url:template,
DataType: "HTML",
Success:function (val) {
$ ("#list"). HTML (Baidu.template (val, data);
}
});

Add template file list.html, which reads as follows

<tableclass= "Table table-bordered" >
<thead>
<tr>
<td> column 1</td>
<td> column 2</td>
<td> column 3</td>
<td> column 4</td>
<td> column 5</td>
<td> column 6</td>
</tr>
</thead>
<%for (var i = 0; i<list.length;i++) {varitem=list[i];%>
<tr>
<td><%=item.col1%></td>
<td><%=item.col2%></td>
<td><%=item.col3%></td>
<td><%=item.col4%></td>
<td><%=item.col5%></td>
<td><%=item.col6%></td>
</tr>
<%}%>
</table>

3, add Default.aspx page, and add Reference

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "Baidutemplate.default"%>
<! DOCTYPE html>
<metahttp-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<scriptsrc= "Js/jquery.min.js" ></script>
<scriptsrc= "Js/baidutemplate.js" ></script>
<scriptsrc= "Js/list.js" ></script>
<linkhref= "Styles/bootstrap.css" rel= "stylesheet"/>
<body>
<formid= "Form1" runat= "Server" >
<divid= "List" style= "margin-top:10px;" >
</div>
</form>
</body>

Preview Effect:

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.