repeater控件如何嵌套? 30
前台的代码就是repeater1里面的一个td里面装着repeater2后台代码是这样,可是因为是嵌套repeater2不可以,要怎么实现呢??protectedvoid...
前台的代码就是repeater1里面的一个td里面装着repeater2
后台代码是这样,可是因为是嵌套repeater2不可以,要怎么实现呢??
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection(@"Server =.; Initial Catalog =test; uid = sa; pwd =12345asdfg");
SqlDataAdapter objCommand = new SqlDataAdapter("select * from leave", objConn);
DataSet ds = new DataSet();
objCommand.Fill(ds);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 4;
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
objPds.CurrentPageIndex = CurPage - 1;
Label3.Text = "第" + CurPage.ToString() + "页/共" + objPds.PageCount.ToString()+"页";
if (!objPds.IsFirstPage)
{
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
}
if (!objPds.IsLastPage)
{
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(objPds.PageCount);
}
Repeater1.DataSource = objPds;
Repeater1.DataBind();
} 展开
后台代码是这样,可是因为是嵌套repeater2不可以,要怎么实现呢??
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection(@"Server =.; Initial Catalog =test; uid = sa; pwd =12345asdfg");
SqlDataAdapter objCommand = new SqlDataAdapter("select * from leave", objConn);
DataSet ds = new DataSet();
objCommand.Fill(ds);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 4;
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
objPds.CurrentPageIndex = CurPage - 1;
Label3.Text = "第" + CurPage.ToString() + "页/共" + objPds.PageCount.ToString()+"页";
if (!objPds.IsFirstPage)
{
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
}
if (!objPds.IsLastPage)
{
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(objPds.PageCount);
}
Repeater1.DataSource = objPds;
Repeater1.DataBind();
} 展开
1个回答
展开全部
html代码如下,将repeater3放到repeater2中
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound">
<ItemTemplate>
<div id='tab<%# Eval("id")%>'>
<asp:Repeater ID="Repeater3" runat="server">
<ItemTemplate>
<div class="item" id='item<%# Eval("id")%>'>
在repeater2的 OnItemDataBound事件中对repeat3的数据进行绑定,代码如下:
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
switch (e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
{
Repeater rpMenu = (Repeater)e.Item.FindControl("Repeater3");
if ((rpMenu.DataSource as DataTable) != null)
{
(rpMenu.DataSource as DataTable).Dispose();
rpMenu.DataSource = null;
}
string id = DataBinder.Eval(e.Item.DataItem, "id").ToString();
string sql="se...........";
rpMenu.DataSource = ..........
rpMenu.DataBind();
}
break;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询