webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="work028.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>数据绑定表达式</title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<%# userName %><br />
博客地址:<%# blogURL %><br />
当前时间:<%# GetDateTime() %><br />
<!--以上绑定方式,如果数据量大,容易造成页面运行效率低下的问题,请慎用-->
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace work028
{
public partial class WebForm1 : System.Web.UI.Page
{
protected string userName = "虾米大王";
public string blogURL = "http://blog.csdn.net/modern358";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Page.DataBind();
}
}
public string GetDateTime()
{
return DateTime.Now.ToString("yyyy-MM-dd");
}
}
}