asp.net repeat嵌套

来源:未知 责任编辑:责任编辑 发表时间:2015-09-16 20:04 点击:


Bind to the Parent Table
1. Start Microsoft Visual Studio .NET.
2. On the File menu, point to New, and then click Project.
3. Click Visual C# Projects under Project Types, and then click ASP.NET Web Application underTemplates.
4. In the Location box, delete the WebApplication#, and then type NestedRepeater. If you use the local server, leave the server name as http://localhost. The following path appears in the Location box:
http://localhost/ NestedRepeater
Click OK.
5. In Solution Explorer, right-click the NestedRepeater project name node, point to Add, and then clickAdd Web Form.
6. To name the Web Form, type NestedRepeater, and click Open.
7. The new Web Form is created. It opens in Design View in the Integrated Development Environment (IDE) of Microsoft Visual Studio .NET. From the Toolbox, select the Repeater control, and then drag it to the Web Form page.
8. Change the ID property of this Repeater control to parentRepeater.
9. Switch to the HTML view for this Web Form. To do so, click the HTML tab in the lower-left corner of the Designer. The Repeater control generates the following HTML code:
10. <asp:Repeater id="parentRepeater" runat="server"></asp:Repeater>
     
11. Add the following code in the Repeater tags:
12. <itemtemplate>
13.      <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>
14. </itemtemplate>
     
After you do that, the HTML code for the Repeater is as follows:
<asp:Repeater id="parentRepeater" runat="server">
 <itemtemplate>
      <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br> 
      </itemtemplate>
</asp:Repeater>
     
15. In Solution Explorer, right-click NestedRepeater.aspx, and then click View Code to switch to the NestedRepeater.aspx.cs code-behind file.
16. Add the following namespace declaration to the top of the file:
17. using System.Data;
18. using System.Data.SqlClient;
     
19. Add the following code to the Page_Load event to create a connection to the Pubs database, and then to bind the Authors table to the Repeater control:
20.       public void Page_Load(object sender, EventArgs e)
21.       {
22.          //Create the connection and DataAdapter for the Authors table.
23.          SqlConnection cnn = new SqlConnection("server=(local);database=pubs; Integrated Security=SSPI");

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • asp.net 设置GridView的选中行的实现代码
  • C#高级编程:数据库连接[1]
  • ASP.NET&#160;GridView列表代码示例
  • 经典C++程序1
  • 微软ASP.NET站点部署指南(2):部署SQL Server Compact数据库
  • 微软ASP.NET站点部署指南(3):使用Web.Config文件的Transforma
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1