protected void gv_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Repeater rp_list = (Repeater)e.Item.FindControl("rp_list");
rp_list.ItemDataBound += new RepeaterItemEventHandler(rp_list_ItemDataBound); DataSet ds = baseinfo.BindInfo("表名", "");
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)
{
//如何获取子repeater中的控件
//Repeater rp_list = (Repeater)e.Item.FindControl("rp_list");
//DataView dv = (DataView)rp_list.DataSource; //Label lb_cg = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_cg");
//lb_cg.Text = cg.ToString();
}
}控件
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Repeater rp_list = (Repeater)e.Item.FindControl("rp_list");
rp_list.ItemDataBound += new RepeaterItemEventHandler(rp_list_ItemDataBound); DataSet ds = baseinfo.BindInfo("表名", "");
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)
{
//如何获取子repeater中的控件
//Repeater rp_list = (Repeater)e.Item.FindControl("rp_list");
//DataView dv = (DataView)rp_list.DataSource; //Label lb_cg = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_cg");
//lb_cg.Text = cg.ToString();
}
}控件
已经试过了 都是null
//Label lb_cg = (Label)rp_list.Controls[rp_list.Controls.Count - 1].FindControl("lb_cg");
Label lb_cg= (Label)e.Item.FindControl("lb_cg");
谢谢!这样可以获取到rp_list中的控件了!(只顾着想办法获取子repeater中的数据源了) //DataView dv = (DataView)rp_list.DataSource;
//怎样才能像这样获取到子repeater中数据源呢?
//object cg = dv.Table.Compute("SUM(cg_money) ", "");
//Label lb_cg = (Label)e.Item.FindControl("lb_cg");
//lb_cg.Text = cg.ToString();我需要像上面这样的代码 做尾部的合计
但是现在获取不到rp_list的数据源
{
Repeater rp_list = (Repeater)item.FindControl("rp_list");
DataView dv = (DataView)rp_list.DataSource;
object cg = dv.Table.Compute("SUM(cg_money) ", "");
Label lb_cg = (Label)e.Item.FindControl("lb_cg");
lb_cg.Text = cg.ToString();
}
这样写的话就可以获取到了。
但是这样有个问题,就是如果我父repeater中有多行,子repeater的合计会累计赋值到最后一个子repeater的尾部去,前面的子repeater合计列都是空的
很纠结```求帮助!