首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

repeater嵌封套repeater的循环绑定

2013-09-05 
repeater嵌套子repeater的循环绑定如题:我在主repeater中嵌套了一个子repeater在给子repeater 绑定时 每个

repeater嵌套子repeater的循环绑定
如题:
我在主repeater中嵌套了一个子repeater
在给子repeater 绑定时 每个子repeater尾部都要有一个合计
但是每次循环绑定时 最后一个子repeater的尾部合计都绑定不了
其他地方都没有问题 不晓得到底是为什么 下面是绑定的代码


//主repeater行绑定
    protected void gv_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string code = Request.QueryString["code"].ToString();
            HiddenField hid_code = (HiddenField)e.Item.FindControl("hid_code");
            Label lb_td = (Label)e.Item.FindControl("lb_td");
            Repeater rp_list = (Repeater)e.Item.FindControl("rp_list");
            rp_list.ItemDataBound += new RepeaterItemEventHandler(rp_list_ItemDataBound);
            DataSet ds = baseinfo.BindInfo("V_成本核算", "类别='材料' and 客户编号=" + int.Parse(code) + " and 部位编号=" + int.Parse(hid_code.Value));

            rp_list.DataSource = ds.Tables[0].DefaultView;
            rp_list.DataBind();
        }
} //子repeater明细绑定事件
    protected void rp_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            foreach (RepeaterItem item in this.gv_list.Items)
            {
                Repeater rp_list = (Repeater)item.FindControl("rp_list");
                DataView dv = (DataView)rp_list.DataSource;
                object sc = dv.Table.Compute("SUM(市场金额) ", "");


                object kh = dv.Table.Compute("SUM(客户金额) ", "");
                object hs = dv.Table.Compute("SUM(核算金额) ", "");
                object cg = dv.Table.Compute("SUM(采购金额) ", "");

                Label lb_sc = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_sc");
                lb_sc.Text = sc.ToString();
                Label lb_kh = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_kh");
                lb_kh.Text = kh.ToString();
                Label lb_hs = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_hs");
                lb_hs.Text = hs.ToString();
                Label lb_cg = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_cg");
                lb_cg.Text = cg.ToString();
            }
        }
    }


[解决办法]
先把子Repeater控件做成一个用户控件,能显示合计,然后把这个用户控件拉入Repeater控件中,这样应该没有问题。
[解决办法]
引用:
如题:
我在主repeater中嵌套了一个子repeater
在给子repeater 绑定时 每个子repeater尾部都要有一个合计
但是每次循环绑定时 最后一个子repeater的尾部合计都绑定不了
其他地方都没有问题 不晓得到底是为什么 下面是绑定的代码



//主repeater行绑定
    protected void gv_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem 
[解决办法]
 e.Item.ItemType == ListItemType.Item)
        {
            string code = Request.QueryString["code"].ToString();
            HiddenField hid_code = (HiddenField)e.Item.FindControl("hid_code");
            Label lb_td = (Label)e.Item.FindControl("lb_td");
            Repeater rp_list = (Repeater)e.Item.FindControl("rp_list");
            rp_list.ItemDataBound += new RepeaterItemEventHandler(rp_list_ItemDataBound);
            DataSet ds = baseinfo.BindInfo("V_成本核算", "类别='材料' and 客户编号=" + int.Parse(code) + " and 部位编号=" + int.Parse(hid_code.Value));

            rp_list.DataSource = ds.Tables[0].DefaultView;
            rp_list.DataBind();
        }
} //子repeater明细绑定事件
    protected void rp_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            foreach (RepeaterItem item in this.gv_list.Items)
            {
                Repeater rp_list = (Repeater)item.FindControl("rp_list");
                DataView dv = (DataView)rp_list.DataSource;
                object sc = dv.Table.Compute("SUM(市场金额) ", "");
                object kh = dv.Table.Compute("SUM(客户金额) ", "");


                object hs = dv.Table.Compute("SUM(核算金额) ", "");
                object cg = dv.Table.Compute("SUM(采购金额) ", "");

                Label lb_sc = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_sc");
                lb_sc.Text = sc.ToString();
                Label lb_kh = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_kh");
                lb_kh.Text = kh.ToString();
                Label lb_hs = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_hs");
                lb_hs.Text = hs.ToString();
                Label lb_cg = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_cg");
                lb_cg.Text = cg.ToString();
            }
        }
    }


好好的思路repeater嵌封套repeater的循环绑定
[解决办法]
你这个子Repeater的合计,绑定的数据加一个合计查询字段。
[解决办法]
自己调试看看啊,要学会找问题
[解决办法]
应该是事件 顺序 问题。你在子控件的绑定事件里 要遍历父控件,你怎么知道父控件绑定完成了?

热点排行