我有以下要求,1.需要显示不同的apName。2. 对于每个 apName,显示费率。
到目前为止我已经尝试过了,
在 .cs 页面上
protected void btn_ViewClick(object sender, EventArgs e)
{
//bind the repeater control, with the Data Table
rptApartmentName.DataSource = rate.GetAllApartmentRates();
rptApartmentName.DataBind();
}
private void rptApartmentName_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
{
Repeater rptRates = (Repeater)item.FindControl("rptRates");
DataRowView drv = (DataRowView)item.DataItem;
rptRates.DataSource = drv.CreateChildView("apartment_rate");
rptRates.DataBind();
}
}
在 aspx 页面上,
<!-- start parent repeater -->
<asp:repeater id="rptApartmentName" runat="server" OnItemDataBound="rptApartmentName_ItemDataBound">
<itemtemplate>
<b><%# DataBinder.Eval(Container.DataItem,"apName") %></b><br>
<!-- start child repeater -->
<asp:repeater id="rptRates" runat="server">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "rate")%><br>
</itemtemplate>
</asp:repeater>
<!-- end child repeater -->
</itemtemplate>
</asp:repeater>
<!-- end parent repeater -->
请有人建议,此代码有什么问题,在此先感谢。我正在使用 Asp.Net 2010。
堆栈跟踪:
Line 96: Repeater rptRates = (Repeater)item.FindControl("rptRates");
Line 97: DataRowView drv = (DataRowView)item.DataItem;
Line 98: rptRates.DataSource = drv.CreateChildView("apartment_rate");
Line 99: rptRates.DataBind();
Line 100: }
我在第 98 行遇到错误,因为 System.ArgumentException:关系不是此 DataView 指向的表的父级。