asp.net:repeater嵌套(常用于新闻等在首页归类显示)
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嵌套(常用于新闻等在首页归类显示)的更多相关文章
- ASP.NET Repeater嵌套Repeater实现菜单加载
		
在KS系统中要实现从数据库中读取界面权限文件实现菜单.界面的动态加载. 效果图: ASP.NET界面代码 <div id="menu-container"> <a ...
 - [ASP.NET]asp.net Repeater控件的使用方法
		
asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...
 - ASP.NET中的常用快捷键
		
想查找ASP.NET中的属性快捷键,忘记了,搜了一下,找到了ASP.NET中的常用快捷键. 大神文章:http://www.cnblogs.com/xiacao/archive/2012/06/12/ ...
 - ASP.NET repeater添加序号列的方法
		
ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...
 - 使用Word API打开Word文档   ASP.NET编程中常用到的27个函数集
		
使用Word API(非Openxml)打开Word文档简单示例(必须安装Word) 首先需要引入参照Microsoft.Office.Interop.Word 代码示例如下: public void ...
 - discuz 修改亮剑积分商城2.91模板(在常用设置中添加商场首页排序方式的背景颜色)
		
在应用 -> 积分商城 -> 常用设置 中添加 商场首页排序方式 的背景颜色修改功能 步骤: 1.找到并打开此页面对应的模板source\plugin\aljsc\template\set ...
 - phpstorm常用快捷键有哪些(图解归类)
		
phpstorm常用快捷键有哪些(图解归类) 一.总结 一句话总结: 10.方法参数提示,显示默认参数 解答:--------CTRL+P 13.显示类层级关系图,继承/实现关系 解答:--- ...
 - ASP.NET- 查找Repeater控件中嵌套的控件
		
如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...
 - asp.net repeater控件操作
		
Repeater控件和DataList控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...
 
随机推荐
- [CODEVS3299]有序数组合并求第K大问题
			
题目描述 Description 给出两个有序数组A和B(从小到大有序),合并两个有序数组后新数组c也有序,询问c数组中第k大的数 假设不计入输入输出复杂度,你能否给出一个O(logN)的方法? 输入 ...
 - UVa1449 - Dominating Patterns(AC自动机)
			
题目大意 给定n个由小写字母组成的字符串和一个文本串T,你的任务是找出那些字符串在文本中出现的次数最多 题解 一个文本串,多个模式串,这刚好是AC自动机处理的问题 代码: #include <i ...
 - List使用Foreach 修改集合时,会报错的解决方案 (Error: Collection was modified; enumeration operation may not execute. ) - 摘自网络
			
当用foreach遍历Collection时,如果对Collection有Add或者Remove操作时,会发生以下运行时错误: "Collection was modified; enume ...
 - HTTP的升级产品:SPDY
			
一.什么是SPDY? SPDY是Google开发的基于传输控制协议(TCP)的应用层协议 .目前已经被用于Google Chrome浏览器中来访问Google的SSL加密服务.SPDY当前并不是一个标 ...
 - sql中用逗号拼接字符串
			
MSSQL中可以用STUFF函数拼接成字符串. 如: SELECT FieldSomeElse, ( SELECT STUFF(( SELECT ',' + LinkField FROM Detail ...
 - Spring源码入门——AnnotationBeanNameGenerator解析
			
---恢复内容开始--- 接上篇,上篇解析了DefaultBeanGenerator生成bean name的过程(http://www.cnblogs.com/jason0529/p/5272265. ...
 - js 复制网页内容,兼容各浏览器
			
因需要做一个js单击,复制当前网页url的功能.使用的是如下的方法,但是只能在ie浏览器下正常使用. 方法如下: function copyURL(){ var clipBoardContent=&q ...
 - GridControl 复合表头(多行标题)
			
说明: 最好是通过编辑视图进行设计,后台编码有点麻烦. 例图:(上面的GC是后台编写 ,下面的是设计器设计) 后台代码编写: public void InitCtrl() { DevExpress.X ...
 - 杀死当前Excel进程
			
说明: 代码编写过程中,有时需要杀死当前Excel进程,而不影响其他Excel进程. 代码如下: 添加引用: //杀死当前进程的API引用 using System.Runtime.InteropSe ...
 - SQLite数据库如何存储和读取二进制数据
			
SQLite数据库如何存储和读取二进制数据 1. 存储二进制数据 SQLite提供的绑定二进制参数接口函数为: int sqlite3_bind_blob(sqlite3_stmt*, int, co ...