using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
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 index : System.Web.UI.Page
{
protected Repeater childRepeater;//parentRepeater;
public index()
{
Page.Init += new EventHandler(Page_Init);
}
public void Page_Load(object sender, EventArgs e)
{

//Create the connection and DataAdapter for the Authors table.//创建连接,DataAdapter作者表.
string s = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\xlgameguide.mdf;Integrated Security=True;Connect Timeout=30";
SqlConnection con = new SqlConnection(s);
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from gamestyle", con);
//Create and fill the DataSet.//创建和填充数据集。
DataSet ds = new DataSet();
cmd1.Fill(ds, "fenlei");
//Create a second DataAdapter for the Titles table.//创建第二个DataAdapter的标题表。
SqlDataAdapter cmd2 = new SqlDataAdapter("select * from newswords", con);
cmd2.Fill(ds, "wenzhang");
//Create the relation bewtween the Authors and Titles tables.//创建bewtween作者和标题的关系表。
ds.Relations.Add("myrelation",
ds.Tables["fenlei"].Columns["gamestyleid"],
ds.Tables["wenzhang"].Columns["gamestyleid"]);
//Bind the Authors table to the parent Repeater control, and call DataBind.//作者表绑定到父中继器控制和调用DataBind。
parentRepeater.DataSource = ds.Tables["fenlei"];
Page.DataBind();
//Close the connection.//关闭连接。
con.Close();
cmd1.Dispose();
cmd2.Dispose();

//这段是在页面绑定的格式
//<asp:repeater id="parentRepeater" runat="server">
// <itemtemplate>
// <b><%# DataBinder.Eval(Container.DataItem,"gamestyle") %></b><br>
// <!-- start child repeater -->
// <asp:repeater id="childRepeater" datasource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' runat="server">
// <itemtemplate>
// <%# DataBinder.Eval(Container.DataItem, "[\"newsname\"]")%><br>
// </itemtemplate>
// </asp:repeater>
// <!-- end child repeater -->
// </itemtemplate>
//</asp:repeater>

}
//两个无返回值的必须的方法
private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}

asp.net:repeater嵌套(常用于新闻等在首页归类显示)的更多相关文章

  1. ASP.NET Repeater嵌套Repeater实现菜单加载

    在KS系统中要实现从数据库中读取界面权限文件实现菜单.界面的动态加载. 效果图: ASP.NET界面代码 <div id="menu-container"> <a ...

  2. [ASP.NET]asp.net Repeater控件的使用方法

    asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...

  3. ASP.NET中的常用快捷键

    想查找ASP.NET中的属性快捷键,忘记了,搜了一下,找到了ASP.NET中的常用快捷键. 大神文章:http://www.cnblogs.com/xiacao/archive/2012/06/12/ ...

  4. ASP.NET repeater添加序号列的方法

    ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...

  5. 使用Word API打开Word文档 ASP.NET编程中常用到的27个函数集

    使用Word API(非Openxml)打开Word文档简单示例(必须安装Word) 首先需要引入参照Microsoft.Office.Interop.Word 代码示例如下: public void ...

  6. discuz 修改亮剑积分商城2.91模板(在常用设置中添加商场首页排序方式的背景颜色)

    在应用 -> 积分商城 -> 常用设置 中添加 商场首页排序方式 的背景颜色修改功能 步骤: 1.找到并打开此页面对应的模板source\plugin\aljsc\template\set ...

  7. phpstorm常用快捷键有哪些(图解归类)

    phpstorm常用快捷键有哪些(图解归类) 一.总结 一句话总结: 10.方法参数提示,显示默认参数   解答:--------CTRL+P 13.显示类层级关系图,继承/实现关系   解答:--- ...

  8. ASP.NET- 查找Repeater控件中嵌套的控件

    如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...

  9. asp.net repeater控件操作

    Repeater控件和DataList控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...

随机推荐

  1. C#调用VC dll输出参数

    最近做项目需要把以前Vc写的程序整合到VS2005来,用c#写的,以前VC的动态连接库写好了,重写比较麻烦,让C#调用VC dll就好了.但碰到了一个问题:VC中作为输出参数的char*类型的变量应该 ...

  2. openStack 使用public key登陆

  3. Go Slices: usage and internals

    Introduction Go's slice type provides a convenient and efficient means of working with sequences of ...

  4. Robotium学习笔记三

    以下是从网络上抄录的一些Robotium注意事项 1)有些button没有string,没有text,只能通过index来click这样很不直观,而且button的index并不是固定的,有可能随着控 ...

  5. index of rmvb mp3 rm突破站点入口下载

    首先打开Google,在关键词输入框中输入"index of/"inurl:lib(双引號为英文状态下) ,选择“搜索中文简体网页”选项,回车搜索,得到了一些网页,不要以为这是一些 ...

  6. Bootstrap-下拉框 Combobox

    Bootstrap下拉框 Combobox显示效果如下: 源代码: <select class="combobox"> <option></optio ...

  7. cardslib

    https://github.com/gabrielemariotti/cardslib

  8. [Whole Web, Node.js, PM2] Configuring PM2 for Node applications

    In this lesson, you will learn how to configure node apps using pm2 and a json config file. Let's sa ...

  9. open/close table on mysql

    http://hidba.org/?p=170   我们知道mysql是一个支持多线程的数据库,尤其在innodb存储引擎出现后,对mysql的事务,并发,锁支持得到了极大提高.在高并发的访问的应用场 ...

  10. phpcms 源码分析二:

    这次是逆雪寒的common.inc.php第二部分: <?php /* 明天放假了.今天在写点罗.放假没空写了.要陪老婆,大家看了有什么不明白的.可以跟帖问.我懂的我会回答.谢谢 [/php] ...