Repeater控件嵌套实例,依微软支持内容汉化
2010-01-28 01:05
555 查看
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Create the connection and DataAdapter for the Authors table. //创建用于连接Authors表的connection和DataAdapter对象 SqlConnection cnn = new SqlConnection("server=(local);database=pubs; Integrated Security=SSPI"); SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors", cnn); //Create and fill the DataSet. //创建并填充DataSet对象 DataSet ds = new DataSet(); cmd1.Fill(ds, "authors"); //Create a second DataAdapter for the Titles table. //为Titles表创建第二个DataAdapter对象 SqlDataAdapter cmd2 = new SqlDataAdapter("select * from titleauthor", cnn); cmd2.Fill(ds, "titles"); //Create the relation between the Authors and Titles tables. //为Authors和Titles表创建关联(Relation) ds.Relations.Add("myrelation", ds.Tables["authors"].Columns["au_id"], ds.Tables["titles"].Columns["au_id"]); //Bind the Authors table to the parent Repeater control, and call DataBind. //调用DataBind方法将Authors绑定到parent Repeater控件上 parentRepeater.DataSource = ds.Tables["authors"]; Page.DataBind(); //Close the connection. cnn.Close(); } }
上面是后台,
下面是前台,注意导入命名空间的代码:<%@ Import Namespace="System.Data" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Import Namespace="System.Data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Repeater id="parentRepeater" runat="server"> <itemtemplate> <b> <%# DataBinder.Eval(Container.DataItem, "au_id") %> </b> <br> <asp:repeater id="childRepeater" runat="server" datasource='<%# ((DataRowView)Container.DataItem) .Row.GetChildRows("myrelation") %>' > <itemtemplate> <%# DataBinder.Eval(Container.DataItem, "[/"title_id/"]")%><br> </itemtemplate> </asp:repeater> </itemtemplate> </asp:Repeater> </div> </form> </body> </html>
相关文章推荐
- 在VS2008中使用C#代码打印 RichTextBox 控件的内容[方法采自微软支持][Part 1]
- 在VS2008中使用C#代码打印 RichTextBox 控件的内容[方法采自微软支持][Part 2]
- Repeater控件嵌套--多级目录
- 使用Repeater控件进行数据访问的综合实例
- 解决母版页报错“内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。”
- 微软控件样式及消息分析工具汉化增强版 MicrosoftControlSpyPlug
- 关于GridView,DataList,Repeater控件的嵌套使用
- ASP.NET中repeater控件用法实例
- Repeater嵌套使用实例
- Repeater控件嵌套Repeater控件
- Asp.net 通过Repeater嵌套Repeater循环添加对应的一组控件
- 控件Repeater的嵌套使用
- 通过代码控制repeater中控件的内容
- 解决母版页报错“内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。”
- 使用JS获取Repeater中指定单元格的内容(单元格无控件)
- Repeater控件的嵌套使用、自定义分页及加链接,样式制定源代码。
- Repeater控件的多层嵌套,DataList控件的多层嵌套
- [vs2005sp1]解决母版页报错“内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。”
- Repeater嵌套dropdownlist控件
- 牛腩 45 整合类别管理(1) session未将对象引用设置到对象的实例,repeater控件的使用,linkbutton的删除