关于datalist中嵌套datalist的绑定
在一个datalist中绑定另一个datalist的绑定是不是这样(在第一个datalist数据绑定时激发)写:((DataList)e.Item.FindControl...
在一个datalist中绑定另一个datalist的绑定是不是这样(在第一个datalist数据绑定时激发)写:
((DataList)e.Item.FindControl("dlSmall")).DataSource=ds2.Tables[0];
((DataList)e.Item.FindControl("dlSmall")).DataBind();
可是执行第一句时就出错了..请问高手们该怎样绑定?
提示“未将对象引用设置到对象的实例” 展开
((DataList)e.Item.FindControl("dlSmall")).DataSource=ds2.Tables[0];
((DataList)e.Item.FindControl("dlSmall")).DataBind();
可是执行第一句时就出错了..请问高手们该怎样绑定?
提示“未将对象引用设置到对象的实例” 展开
2个回答
展开全部
<div>
<ul>
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<li><a href='test.aspx?departmentid=<%# Eval("departmentid") %>'><%#Eval("Name") %></a>
<ul> <asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<li><a href='test.aspx?Categoryid=<%# Eval("categoryid") %>'><%#Eval("Name") %></a>
</ItemTemplate>
</asp:Repeater></ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
源代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Repeater1.DataSource = CatalogAccess.GetDepartments();
Repeater1.DataBind();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item =e.Item;
DataRowView drv = (DataRowView)item.DataItem;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpt = (Repeater)item.FindControl("rep");
string departmentId = Convert.ToString(drv.Row["DepartmentId"]);
if (departmentId != null)
{
rpt.DataSource = CatalogAccess.GetCategoriesInDepartment(departmentId);
rpt.DataBind();
}
}
}
<ul>
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<li><a href='test.aspx?departmentid=<%# Eval("departmentid") %>'><%#Eval("Name") %></a>
<ul> <asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<li><a href='test.aspx?Categoryid=<%# Eval("categoryid") %>'><%#Eval("Name") %></a>
</ItemTemplate>
</asp:Repeater></ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
源代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Repeater1.DataSource = CatalogAccess.GetDepartments();
Repeater1.DataBind();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item =e.Item;
DataRowView drv = (DataRowView)item.DataItem;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpt = (Repeater)item.FindControl("rep");
string departmentId = Convert.ToString(drv.Row["DepartmentId"]);
if (departmentId != null)
{
rpt.DataSource = CatalogAccess.GetCategoriesInDepartment(departmentId);
rpt.DataBind();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询