asp.net1.1及2.0方式下的绑定语法有何区别,如何在按预定格式绑定数据;如何多个参数绑定到HyperLink等.请参看下面链接
http://www.15seconds.com/issue/040630.htm
--===------------------------------------------===---
ASP.NET 1.X
1)最简单的绑定语法:
<%# Container.DataItem("expression") %>
使用方法如下:
<asp:Label id="label1" runat="server"
Text='<%# Container.DataItem("CustomerName") %>'
2)如果你希望格式化绑定数据,应该采用下面的语法:
<%# DataBinder.Eval(Container.DataItem, "expression"[, "format"]) %>
使用方法如下:
<asp:Label id="label1" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "OrderDate", _
"{0:dddd d MMMM"]) %>'
Data Binding Statements in ASP.NET 2.0
1)简单绑定
<%# Eval("expression") %>
2)带格式的绑定
<%# Eval("expression"[, "format"]) %>
像在1.1里面那样,你可以做更复杂的绑定:
<%# Eval("Price", "Special Offer {0:C} for Today Only!") %>
3)多列绑定
<asp:HyperLinkField runat="server"
DataTextField="CustomerName"
DataNavigateUrlFields="CustomerID,City"
DataNavigateUrlFormatString=
"http://yoursite.com/showcustomer.aspx?id={0}&city={1}" />
也可以动态编码实现,如下:
void GridView1_Load(object sender, EventArgs e) {
String[] aFields = new String[2];
aFields[0] = "CustomerID";
aFields[1] = "City";
HyperLinkField oHLField = (HyperLinkField) GridView1.Columns[1];
oHLField.DataNavigateUrlFields = aFields;
oHLField.DataNavigateUrlFormatString =
"http://yoursite.com/showcustomer.aspx?id={0}&city={1}"
}
--===------------------------------------------===---
对于XML的绑定,参看下面的链接:
The New Data Binding Syntax for XML Data >>
转载于:https://www.cnblogs.com/flaaash/archive/2008/01/13/1037412.html