这些是我第一次做的,在我做的时候,我总是在想我能不能把标题用后台做出来,我一直都是在想用其它的办法,但是我发现了这个欠套的方法很好很方便;
前台:
<asp:GridView ID="szServerList1" runat="server" AutoGenerateColumns="False" BackColor="White" HorizontalAlign="Center" BorderColor="#E5E6E1" BorderWidth="0px" CellPadding="0">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="2" style="height: 50px" class="style13">
<p><%# DataBinder.Eval(Container.DataItem, "productTypeName")%></p>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="szServer" runat="server" utoGenerateColumns="False" BackColor="White" HorizontalAlign="Center" BorderColor="#E5E6E1" BorderWidth="0px" CellPadding="0" Width="499" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).CreateChildView("tableRelation") %>' DataKeyNames="type"
PageIndex="6">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="border:solid 1px #E5E6E1; width:499px;">
<tr>
<td rowspan="4" style="width:120px;border-right:1px solid #E5E6E1; padding-top:5px;">
<img src="images/1u1.gif" />
</td>
</tr>
<tr>
<td style="width:60px;" >产品名称:</td>
<td><%# DataBinder.Eval(Container.DataItem, "prName")%></td>
</tr>
<tr>
<td style="width:60px;">产品价格:</td>
<td><%# DataBinder.Eval(Container.DataItem, "prMoney")%></td>
</tr>
<tr>
<td style="width:60px;">产品简介:</td>
<td><%# DataBinder.Eval(Container.DataItem, "prSynopsis")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BorderWidth="1" Height="1" />
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
//欠套的asp:GridView 查询前台显示多个类别
DataSet ds = new DataSet();
ds.Tables.Add(CDB.FillTable("select * from productType"));
ds.Tables[0].TableName = "Type1";
ds.Tables.Add(CDB.FillTable("select * from [production] join [productType] on production.type=productType.productTypeID join [productTypeList] on productTypeList.id=production.topType where production.type in (1,2,3)"));
ds.Tables[1].TableName = "TypeList";
DataColumn Parent = ds.Tables["Type1"].Columns["productTypeId"];
DataColumn Child = ds.Tables["TypeList"].Columns["type"];
DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child, true);
ds.Relations.Add(tableRelation);
szServerList1.DataSource = ds.Tables["Type1"].DefaultView;
szServerList1.DataBind();
ds.Clear();
浙公网安备 33010602011771号