asp.net 2.0 repeater 前台报错
前台代码:<asp:RepeaterID="Repeater1"runat="server"OnItemDataBound="Repeater1_ItemDataBoun...
前台代码:
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<div class="MenuChapter">
<a href="default.aspx?id=<%#Eval("id") %>" onclick="return ToggleMenu('Class<%#Eval("id") %>');">
<%#Eval("title") %>
</a>
</div>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<div class="MI" id="Section<%#Eval("id") %>">
<a href="default.aspx?id=<%#Eval("id") %>">
<%#Eval("title") %>
</a>
</div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
string sqlstr = "select * from y_category where pid=0";
help.RepeaterBind(sqlstr, null, Repeater1);
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
DataRowView rowv = (DataRowView)e.Item.DataItem;
int typeid = (Int32)rowv["id"];
help.RepeaterBind("select * from y_category where pid=" + Convert.ToInt32(typeid) + " order by orderby desc,id", null, rep);
}
}
报错:
无法将类型为“System.Data.Common.DataRecordInternal”的对象强制转换为类型“System.Data.DataRowView”。 【第26行】
源错误:
行 24: {
行 25: Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
行 26: DataRowView rowv = (DataRowView)e.Item.DataItem;
行 27: int typeid = (Int32)rowv["id"];
行 28: help.RepeaterBind("select * from y_category where pid=" + Convert.ToInt32(typeid) + " order by orderby desc,id", null, rep); 展开
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<div class="MenuChapter">
<a href="default.aspx?id=<%#Eval("id") %>" onclick="return ToggleMenu('Class<%#Eval("id") %>');">
<%#Eval("title") %>
</a>
</div>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<div class="MI" id="Section<%#Eval("id") %>">
<a href="default.aspx?id=<%#Eval("id") %>">
<%#Eval("title") %>
</a>
</div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
string sqlstr = "select * from y_category where pid=0";
help.RepeaterBind(sqlstr, null, Repeater1);
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
DataRowView rowv = (DataRowView)e.Item.DataItem;
int typeid = (Int32)rowv["id"];
help.RepeaterBind("select * from y_category where pid=" + Convert.ToInt32(typeid) + " order by orderby desc,id", null, rep);
}
}
报错:
无法将类型为“System.Data.Common.DataRecordInternal”的对象强制转换为类型“System.Data.DataRowView”。 【第26行】
源错误:
行 24: {
行 25: Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
行 26: DataRowView rowv = (DataRowView)e.Item.DataItem;
行 27: int typeid = (Int32)rowv["id"];
行 28: help.RepeaterBind("select * from y_category where pid=" + Convert.ToInt32(typeid) + " order by orderby desc,id", null, rep); 展开
2个回答
展开全部
e.Item.DataItem的原形是System.Data.Common.DataRecordInternal也就是说你在help.RepeaterBind(sqlstr, null, Repeater1);中给e.Item.DataItem绑定的对像是System.Data.Common.DataRecordInternal,而System.Data.Common.DataRecordInternal和System.Data.DataRowView是无法转化的。
改:Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
System.Data.Common.DataRecordInternal rowv = (System.Data.Common.DataRecordInternal)e.Item.DataItem;
……
改:Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
System.Data.Common.DataRecordInternal rowv = (System.Data.Common.DataRecordInternal)e.Item.DataItem;
……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询