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();
}
展开
 我来答
zhenxin0603
2014-11-10 · TA获得超过600个赞
知道小有建树答主
回答量:600
采纳率:100%
帮助的人:452万
展开全部

         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;
                    }
            }
        }
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式