DataList 嵌套DataList ,怎么进行数据绑定啊。我已经在.cs文件里建了个DataRelation

dongyp511 2004-04-12 09:05:12
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="0">
<TR>
<TD>
<asp:Label id=lblUserDescription runat="server" text='<%# DataBinder.Eval(Container, "DataItem.UserDescription") %>'>
</asp:Label></TD> </TR><TR><TD> <asp:DataList id="DataList2" runat="server" DataSource='<%# ((Row)Container.DataItem).GetChildRows("RelatedTypeRel") %>'>
<ItemTemplate>
<a href='<%# String.Format("ProductDetail.aspx?ProductId={0}&categoryId={1}", DataBinder.Eval(Container.DataItem,"ProductId"), DataBinder.Eval(Container.DataItem,"CategoryId"))%>'>
<%# DataBinder.Eval(Container, "DataItem.Name") %>
--<%# DataBinder.Eval(Container, "DataItem.Description") %>:<%# DataBinder.Eval(Container, "DataItem.ActualPrice") %>
</a>
</ItemTemplate>
</asp:DataList></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:DataList>




<asp:DataList id="DataList2" runat="server" DataSource='<%# ((Row)Container.DataItem).GetChildRows("RelatedTypeRel") %>'>
总是说有问题!! 我要怎么写把 另个关联表绑定到嵌套的那个datalist啊?
...全文
225 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujiayu10 2004-04-12
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=149E5DD7-3B32-461e-ACC6-51D1652E6746
xiaoyan21 2004-04-12
  • 打赏
  • 举报
回复
看看你的DataRelation
我做过一个,不难实现啊...

<asp:datalist id="DataList2" width="100%" runat="server" datasource='<%# ((DataRowView)Container.DataItem).CreateChildView("OrderRelation") %>'>
DawnJ 2004-04-12
  • 打赏
  • 举报
回复
dataGrid内嵌datalist



public void ClassDG_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>=0)
{
string name=e.Item.Cells[1].Text;
string Sql2="Select Class2_Id,Class2_Name from Class2_Table where Class1_ID='"+name+"'";
DataSet Ds=new DataSet();
Ds=my.DbBind(Sql2,"Class2");
((DataList)e.Item.FindControl("DataList1")).DataSource=Ds.Tables["Class2"].DefaultView;
((DataList)e.Item.FindControl("DataList1")).DataBind();
}

}
dongyp511 2004-04-12
  • 打赏
  • 举报
回复
<asp:DataGrid runat=server id=dgDetails
DataSource=<%# GetDetails(container.dataitem("EmployeeID"))%>
有问题呀

编译器错误信息: CS0118: “System.Web.UI.WebControls.DataListItem.DataItem”表示“属性”,此处应为“方法”

我是用c#写的 是不是要改什么东西???

andrawsky 2004-04-12
  • 打赏
  • 举报
回复
up
liujiayu10 2004-04-12
  • 打赏
  • 举报
回复
楼上的说的对,用DATAGRID的不错,MS已经有现成了,
zhyx21century 2004-04-12
  • 打赏
  • 举报
回复
这是国外Nested DataGrid得一个列子,你自己看看吧
An old Swedish proverb advises that "God gives every bird his worm, but He does not throw it into the nest." Let's check out a nested datagrid, which allows for the presentation of data in a "master/detail" format.

The Outer Grid

The outer datagrid will be relatively simple, returning a NorthWind rep and an adjoining blank cell for the details.

<asp:datagrid runat=server id=dgMaster autogeneratecolumns="False">
<columns>
<asp:BoundColumn HeaderText="Salesperson" DataField=LastName></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Last Five Sales">
<ItemTemplate>
<!-- WE'LL PUT A DATAGRID IN HERE -->
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

and in the code behind,

' this goes in the PageLoad
dgMaster.DataSource = GetAuthors()
dgMaster.DataBind()


' and this is separate
Function GetAuthors() As DataTable
Dim ds As New DataSet()
Dim conn As New SqlConnection("server=std04;uid=sa;pwd=;database=northwind")
Dim strSQL As String
strSQL = "SELECT lastname, EmployeeID FROM Employees ORDER BY lastname"
Dim da As New SqlDataAdapter(strSQL, conn)
da.Fill(ds, "tblAuthors")
Return ds.Tables("tblAuthors")
End Function

which gives us this homely shell -



The Inner Grid

Between the ItemTemplate tags in the first grid, place a second one,

<asp:DataGrid runat=server id=dgDetails
DataSource=<%# GetDetails(container.dataitem("EmployeeID"))%>
AutoGenerateColumns=false>
<Columns>
<asp:BoundColumn DataField="CDATE" HeaderText="Date"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="Product"></asp:BoundColumn>
<asp:BoundColumn DataField="CompanyName" HeaderText="Customer"></asp:BoundColumn>
</Columns>
</asp:DataGrid>

and put the GetDetails function in the codebehind.

Function GetDetails(ByVal x As String)
Dim conn As New SqlConnection("server=std04;uid=sa;pwd=;database=northwind")
Dim strSQL As String
Dim ds As New DataSet()

strSQL = "SELECT TOP 5 Customers.CompanyName, Products.ProductName, "
strSQL &= "convert(varchar, Orders.Orderdate, 101) as CDATE "
strSQL &= "FROM Employees INNER JOIN "
strSQL &= "Orders ON Employees.EmployeeID = Orders.EmployeeID INNER JOIN "
strSQL &= "Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN "
strSQL &= "[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN "
strSQL &= "Products ON [Order Details].ProductID = Products.ProductID "
strSQL &= "WHERE Employees.EmployeeID = " & x & " ORDER BY orderdate DESC"

Dim da As New SqlDataAdapter(strSQL, conn)
da.Fill(ds, "tblDetails")
Return ds.Tables("tblDetails")
End Function

What just happened? We set the datasource of the inner datagrid by passing the employee id to the GetDetails function, which returns a table with the last five orders. It's that simple. Even the databinding happens automatically. Behold final product of the nested datagrid.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧