Repeater嵌套GridView实现主细表
控件:
<div style="text-align:center">
<asp:Repeater ID="Repeater" runat="server">
<ItemTemplate>
<table border="1">
<tr><td><%#Eval("name") %> </td></tr>
<tr>
<td>
<asp:GridView ID="GridView" DataSource='<%#((System.Data.DataRowView)Container.DataItem).CreateChildView("dr") %>' runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical">
<Columns>
<asp:BoundField DataField="name" HeaderText="名称" ItemStyle-Width="200"/>
<asp:BoundField DataField="price" DataFormatString="{0}¥" HeaderText="价格" ItemStyle-Width="200"/>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
数据绑定:
string sql = "select * from type;select * from product";
DataSet ds = da.GetDataSet(sql);
DataRelation dr = new DataRelation("dr", ds.Tables[0].Columns["id"], ds.Tables[1].Columns["type"]);
ds.Relations.Add(dr);
this.Repeater.DataSource = ds.Tables[0];
this.Repeater.DataBind();
显示效果:
------解决方案--------------------??什么意思啊
------解决方案--------------------你用datalist嵌套看看
------解决方案--------------------用 datalist嵌套gridview 数据绑定
------解决方案--------------------老大的blog
http://blog.csdn.net/net_lover/archive/2006/12/10/1437535.aspx
------解决方案--------------------
------解决方案--------------------经过测试的,改下你的字段、表和提取数据方法即可。
前台:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
id:<%#Eval("ID")%>
carid:<%#Eval("car_id")%>
<asp:GridView ID="inGridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="name1" HeaderText="name1" SortExpression="name1" />