请教各位高手!如何在asp.net页面上动态显示多重主从表(BOM)

jujuyun 2008-12-01 10:27:25
请教各位高手!如何在asp.net页面上动态显示多重主从表(BOM),显示效果如下图,要求点击前面“+”时能显示子表,点“-”时隐藏子表,可能会有很多层。请教各位有什么好办法!
...全文
207 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jujuyun 2008-12-02
  • 打赏
  • 举报
回复
我要的是很多层的
qinhl99 2008-12-02
  • 打赏
  • 举报
回复
如果你是两级的话,很好办
1、在DataList的<SelectedItemTemplate>列下放一个DataGrid或者GridView,
2、在DataList的ItemDataBound事件去帮定DataGrid或者GridView的数据
3、实现DataList的ItemCommand事件,dtlist.SelectedIndex = e.Item.ItemIndex;这样就可以显示了
jujuyun 2008-12-02
  • 打赏
  • 举报
回复
这种GridView嵌套是可以做到的,但效果不是很好,不知道有没有更好的办法。
cwmwss 2008-12-02
  • 打赏
  • 举报
回复
这是两层的。自己看能修改成三层的不
cwmwss 2008-12-02
  • 打赏
  • 举报
回复
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Country] FROM [Customers]">
</asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound"
Width="60%">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="CustomerID" SortExpression="CustomerID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<table style="width: 100%">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Text='<%# Bind("CustomerID") %>'></asp:Label>
<strong>-</strong>
<asp:Label ID="Label2" runat="server" Font-Bold="True" Text='<%# Eval("CompanyName") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None" Visible="False">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="Customer ID" />
<asp:BoundField DataField="OrderID" HeaderText="Order ID" />
<asp:BoundField DataField="OrderDate" HeaderText="Order Date" />
</Columns>
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID],[OrderID], [OrderDate] FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
<SelectParameters>
<asp:Parameter Name="CustomerID" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle VerticalAlign="Top" Width="10%" />
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Show" Text="Show" Width="75px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
cwmwss 2008-12-02
  • 打赏
  • 举报
回复
public partial class Control_MasterDetail : System.Web.UI.Page
{
private int index = 0;

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button b = (Button)e.Row.Cells[1].FindControl("Button1");
b.CommandArgument = index.ToString();
index = index + 1;
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Show")
{
Button b = (Button)GridView1.Rows[int.Parse(e.CommandArgument.ToString())].Cells[1].FindControl("Button1");
if (b.Text == "Show")
{
string custid = GridView1.DataKeys[int.Parse(e.CommandArgument.ToString())].Value.ToString();
SqlDataSource sds = (SqlDataSource)GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("SqlDataSource2");
GridView gv = (GridView)GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("GridView2");
sds.SelectParameters[0].DefaultValue = custid;
gv.Visible = true;
b.Text = "Hide";
}
else
{
GridView gv = (GridView)GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("GridView2");
gv.Visible = false;
b.Text = "Show";
}

}
}
}
wanghao3616 2008-12-01
  • 打赏
  • 举报
回复
除了数据控件嵌套绑定 还能有什么方法啊
你还想怎么办 搞成动态的 ?
点加好读取
jujuyun 2008-12-01
  • 打赏
  • 举报
回复
圖片如下:好像利用Repeater控件可以,可我不太明白怎樣做,要多層的。

62,046

社区成员

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

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

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

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