Mastering DataBinding In Asp.net
2007-04-24 12:20
453 查看
<%# DataBinder.Eval(Container.DataItem, "customerId") %>
<%# ((DataRowView)Container.DataItem)["customerId"] %>
<%# ((User)Container.DataItem).UserName%>
<%# FormatDate(DataBinder.Eval(Container.DataItem, "Ordered"))%>
<%# FormatMoney(DataBinder.Eval(Container.DataItem, "Amount"))%>
Visible='<%# (int)DataBinder.Eval(Container.DataItem, "Pets.Count") > 0 %>'>
后台:
protected void itemDataBoundRepeater_ItemDataBound(object source,
ds.Relations.Add(new DataRelation("CustomerOrders",
ds.Tables[0].Columns["CustomerId"],
ds.Tables[1].Columns["CustomerId"]));
DataSource='<%# ((DataRowView)Container.DataItem).CreateChildView("CustomerOrders")%>'
DataSource='<%# DataBinder.Eval(Container.DataItem, "CutomerOrders")%>'
DataSource="<%# ((Owner)Container.DataItem).Pets%>"
DataSource='<%# DataBinder.Eval(Container.DataItem, "Pets")%>'
protected void dataSetCasting_ItemDataBound(object s,
2<asp:LinkButton ID="delete"
2 Runat="server"
3 CommandName="Delete"
4 CommandArgument='<%# DataBinder.Eval(Container.DataItem,
5 "CustomerId") %>'>
1 protected void eventRepeater_ItemCommand(object s,
2
3 RepeaterCommandEventArgs e) {
4 int customerId = Convert.ToInt32(e.CommandArgument);
5 switch (e.CommandName.ToUpper()){
6 case "DELETE":
7 CustomerUtility.DeleteCustomer(customerId);
8 BindEventRepeater(false);
9 break;
10 case "Add":
11 //doesn't actually do antyhing right now.
12 break;
13 }
14 }
DataItem:如果你用的数据源是Table、DataSet之类的话,那么它可以强制类型转换为DataRowView;如果你用的是自定义实体集合,那么它可以强制类型转换为相应的实体。
<%# ((DataRowView)Container.DataItem)["customerId"] %>
<%# ((User)Container.DataItem).UserName%>
<%# FormatDate(DataBinder.Eval(Container.DataItem, "Ordered"))%>
<%# FormatMoney(DataBinder.Eval(Container.DataItem, "Amount"))%>
Visible='<%# (int)DataBinder.Eval(Container.DataItem, "Pets.Count") > 0 %>'>
后台:
protected void itemDataBoundRepeater_ItemDataBound(object source,
ds.Relations.Add(new DataRelation("CustomerOrders",
ds.Tables[0].Columns["CustomerId"],
ds.Tables[1].Columns["CustomerId"]));
DataSource='<%# ((DataRowView)Container.DataItem).CreateChildView("CustomerOrders")%>'
DataSource='<%# DataBinder.Eval(Container.DataItem, "CutomerOrders")%>'
DataSource="<%# ((Owner)Container.DataItem).Pets%>"
DataSource='<%# DataBinder.Eval(Container.DataItem, "Pets")%>'
protected void dataSetCasting_ItemDataBound(object s,
2<asp:LinkButton ID="delete"
2 Runat="server"
3 CommandName="Delete"
4 CommandArgument='<%# DataBinder.Eval(Container.DataItem,
5 "CustomerId") %>'>
1 protected void eventRepeater_ItemCommand(object s,
2
3 RepeaterCommandEventArgs e) {
4 int customerId = Convert.ToInt32(e.CommandArgument);
5 switch (e.CommandName.ToUpper()){
6 case "DELETE":
7 CustomerUtility.DeleteCustomer(customerId);
8 BindEventRepeater(false);
9 break;
10 case "Add":
11 //doesn't actually do antyhing right now.
12 break;
13 }
14 }
DataItem:如果你用的数据源是Table、DataSet之类的话,那么它可以强制类型转换为DataRowView;如果你用的是自定义实体集合,那么它可以强制类型转换为相应的实体。
相关文章推荐
- Simplified and Extended Data Binding Syntax in ASP.NET 2.0(part1)
- Simplified and Extended Data Binding Syntax in ASP.NET 2.0 -- Cont'd
- Simplified and Extended Data Binding Syntax in ASP.NET 2.0
- 捆绑语法详解 Simplified and Extended Data Binding Syntax in ASP.NET 2.0
- using Silverlight 4 in an ASP.NET MVC 3 application and accessing data with JSON
- Link ASP.NET Data Grid to Microsoft Excel in the client side
- Mastering Caching in Asp.net
- Model Binding in ASP.NET MVC
- asp.net错误解决:Unable to Validate Data in ASP.NET website
- Displaying Data in a Chart with ASP.NET Web Pages (Razor)
- Parameter Binding in ASP.NET Web API(参数绑定)
- User Secrets – Storing sensitive data in ASP.NET Core projects
- Container.DataItem is faster than Eval in ASP.NET
- NetTcpBinding In IIS7.0 ASP.NET v4.0
- ASP.NET MVC 2.0 in Vs2010 :使用C# 4.0中使用动态类型来传递ViewData
- Server-side ASP .NET Data Binding, Part 2: Customizing the DataGrid Control
- Asp.Net Web API 2第十六课——Parameter Binding in ASP.NET Web API(参数绑定)
- ASP.NET DropDownList with XML Databinding
- asp.net 异常:"DataBinding: 'System.Data.DataRowView'
- Working with Data in ASP.NET 2.0 :: Using TemplateFields in the GridView Control