Repeater1 嵌套 为何会加载所有数据?
private void ShowMe(){
XDocument xdoc = XDocument.Load(Server.MapPath("~/XMLFile/qjrztype.xml"));
var hdong = from p in xdoc.Descendants("pereson") orderby int.Parse( p.Element("sorts").Value) descending select new { id = p.Element("id").Value, titles = p.Element("titles").Value };
Repeater1.DataSource = hdong.ToList();
Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpColumnNews = (Repeater)e.Item.FindControl("Repeater2");
XDocument xdoc = XDocument.Load(Server.MapPath("~/XMLFile/qjrztype.xml"));
var hdong = from p in xdoc.Descendants("pereson") select new { id = p.Element("id").Value};
string id = null;
foreach (var item in hdong)
{
id=item.id;
break;
}
//提取分类ID
XDocument xdoc2 = XDocument.Load(Server.MapPath("~/XMLFile/qqjzinfo.xml"));
var hdong2 = from p in xdoc2.Descendants("pereson") where (p.Element("typeid").Value == id) select new { id = p.Element("id").Value, titles = p.Element("titles").Value, typeid = p.Element("typeid").Value };
rpColumnNews.DataSource = hdong2.ToList();
rpColumnNews.DataBind();
}
}
where (p.Element("typeid").Value == id) 我这里都判断了, 类型不同的也加载进去了,为何呢? --------------------编程问答-------------------- 代码整理整理 --------------------编程问答-------------------- 为什么会这样呢? --------------------编程问答-------------------- 怎么没有人用过吗? --------------------编程问答-------------------- 你要先取得关联Repeater的数据项,然后在根据那个数据项取你要关联的值在去查找数据库
DataRowView dr = (DataRowView)e.Item.DataItem;这个是用dataset绑定的
linq只用过1个月,不懂怎么转换,飘过
补充:.NET技术 , ASP.NET