星空网 > 软件开发 > ASP.net

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

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

德国下号问题杂谈(一)店铺和仓库问题:https://www.kjdsnews.com/a/570722.html
Shopify域名和店铺名不一样有影响吗?:https://www.kjdsnews.com/a/570723.html
Shopify怎么防止封号?Shopify封号怎么办?:https://www.kjdsnews.com/a/570724.html
越南海外仓退货服务有吗,哪家越南海外仓好?:https://www.kjdsnews.com/a/570725.html
ONT8和FTW1,是网红仓库,也是死亡仓库:https://www.kjdsnews.com/a/570726.html
Shopee店铺产品上传需要审核吗?:https://www.kjdsnews.com/a/570727.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流