一种新的嵌套绑定的方法
2006-09-25 22:16
197 查看
以前做嵌套,要么是在多次访问数据库,要么是把数据取出来,然后分别使用DataView的RowFilter来做,今天发现了一种新的方法,使用DataSet的Relations可以很方便的做嵌套
方法主要是在dataset的表之间建立关联,然后在前台html视图里使用
DataSource='<%
# ((DataRowView)Container.DataItem).Row.GetChildRows("MyRelation") %>'
具体例子如下:
这里用的是两个repeater嵌套
绑定代码:
Business.Customer obj = new Zeda.CRM.Business.Customer();
DataSet ds = obj.up_CRM_ProductSearchList(this.KeyWord);
ds.Relations.Add("MyRelation",ds.Tables[0].Columns["CustomerId"],ds.Tables[1].Columns["CustomerId"]);
ParentRep.DataSource = ds.Tables[0].DefaultView;
//ParentRep.DataBind();
AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
Page.DataBind();
ds.Dispose();
obj.Dispose();
html视图代码
<asp:repeater id="ParentRep" Runat="server">
<ItemTemplate>
<tr>
<td height=25 width=40%> <a href='CustomerDetail.aspx?CustomerId=<%# DataBinder.Eval(Container.DataItem,"CustomerId")%>'><%
# DataBinder.Eval(Container.DataItem,"Name")%></a></td>
<td><asp:Repeater ID=sonRep Runat=server DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("MyRelation") %>'>
<ItemTemplate>
<a href='ProductDetail.aspx?ProductId=<%# DataBinder.Eval(Container.DataItem,"[ProductId]")%>'><%
# DataBinder.Eval(Container.DataItem, "[/"ProductName/"]")%></a>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
</asp:Repeater></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="1" background="../images/xian01.gif" colspan="2"></td>
</tr>
</SeparatorTemplate>
</asp:repeater>
方法主要是在dataset的表之间建立关联,然后在前台html视图里使用
DataSource='<%
# ((DataRowView)Container.DataItem).Row.GetChildRows("MyRelation") %>'
具体例子如下:
这里用的是两个repeater嵌套
绑定代码:
Business.Customer obj = new Zeda.CRM.Business.Customer();
DataSet ds = obj.up_CRM_ProductSearchList(this.KeyWord);
ds.Relations.Add("MyRelation",ds.Tables[0].Columns["CustomerId"],ds.Tables[1].Columns["CustomerId"]);
ParentRep.DataSource = ds.Tables[0].DefaultView;
//ParentRep.DataBind();
AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
Page.DataBind();
ds.Dispose();
obj.Dispose();
html视图代码
<asp:repeater id="ParentRep" Runat="server">
<ItemTemplate>
<tr>
<td height=25 width=40%> <a href='CustomerDetail.aspx?CustomerId=<%# DataBinder.Eval(Container.DataItem,"CustomerId")%>'><%
# DataBinder.Eval(Container.DataItem,"Name")%></a></td>
<td><asp:Repeater ID=sonRep Runat=server DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("MyRelation") %>'>
<ItemTemplate>
<a href='ProductDetail.aspx?ProductId=<%# DataBinder.Eval(Container.DataItem,"[ProductId]")%>'><%
# DataBinder.Eval(Container.DataItem, "[/"ProductName/"]")%></a>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
</asp:Repeater></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="1" background="../images/xian01.gif" colspan="2"></td>
</tr>
</SeparatorTemplate>
</asp:repeater>
相关文章推荐
- 一种新的嵌套绑定的方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- Asp.Net一种更加优雅的数据绑定方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- WP7容器内动态嵌套自定义容器类并绑定响应函数的方法
- IIS 指定了身份验证方案“IntegratedWindowsAuthentication, Anonymous”,但绑定仅支持一种身份验证的规范。有效的身份验证方案为摘要、协商、NTLM、基本或匿名。解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- from中嵌套from的一种方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- asp.net实现DataList与Repeater嵌套绑定的方法
- 在DataGrid里面绑定ComboBox列时无法在编辑模板下默认选中一个备选值的一种解决方法
- asp.net asp:Repeater嵌套绑定方法(1)
- asp.net中Repeater嵌套绑定的方法(查询新闻类别和新闻类别下的新闻) .
- asp.net中Repeater嵌套绑定的方法(使用两个Repeater做子类别绑定)
- ASP.NET2.0中 TreeView 和ORACLE 数据绑定的一种方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- 一种处理分页控件和绑定数据方法