datalist嵌套gridview
想实现的效果是这样的:类型1
内容1
内容2
内容3
类型2
内容1
内容2
内容3
类型3
内容1
内容2
大家能给个例子吗?多谢了!
--------------------编程问答-------------------- 两个同时查出来,内层的先隐藏,加个触发(如加号)再将内层的显示 --------------------编程问答-------------------- 这是一个外层加了分页的datagrid嵌套datalist的一个例子你可以参考一下,基本差不多的(因为外层加了分页,看起来会麻烦点)
<asp:datagrid id="etw_p" runat="server" AutoGenerateColumns="False" GridLines="None" ShowHeader="False" AllowPaging="True" PageSize="6" OnPageIndexChanged="etw_p_PageIndexChanged" AllowCustomPaging="True" >
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<div class="lm"><b><%#Eval("category_name") %></b></div>
<ul>
<asp:datalist id="etw_pro" runat="server" datasource='<%# DataBinder.Eval(Container, "DataItem.myrelation") %>' RepeatColumns="2" RepeatLayout="Flow">
<itemtemplate>
<li>
<ol>
<li><a href="showproducts.aspx?id=<%#Eval("product_id")%>"><img src="<%#Eval("product_pic") %>" alt="<%#Eval("product_name")%>" width="70" height="74" /></a> </li>
<li class="etw_p"><b><%#Eval("product_name") %>:<%#Eval("product_type") %></b>
descripción: <%#Eval("product_content") %><br />
</li>
</ol>
</li>
</itemtemplate>
</asp:datalist>
</ul>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages" CssClass="pager" />
</asp:datagrid>
protected void BindProduct()
{
OleDbConnection constring = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["xkConnStr"].ConnectionString);
DataSet ds = new DataSet();
intEndIndex = intStartIndex + etw_p.PageSize;
string sql1 = "select * from big_category where category_id > @startIndex and category_id <= @endIndex order by category_id ";
OleDbDataAdapter sda1 = new OleDbDataAdapter(sql1, constring);
sda1.SelectCommand.Parameters.Add("?", OleDbType.Integer).Value = intStartIndex;
sda1.SelectCommand.Parameters.Add("?", OleDbType.Integer).Value = intEndIndex;
sda1.Fill(ds, "biglb");
string sql2 = "select product_id,product_name,product_pic,product_type,category_id,mid(product_content,1,198) as product_content from product where category_id > @startIndex and category_id <= @endIndex and tuijian1=1 order by product_id";
OleDbDataAdapter sda2 = new OleDbDataAdapter(sql2, constring);
sda2.SelectCommand.Parameters.Add("?", OleDbType.Integer).Value = intStartIndex;
sda2.SelectCommand.Parameters.Add("?", OleDbType.Integer).Value = intEndIndex;
sda2.Fill(ds,"product");
ds.Relations.Add("myrelation", ds.Tables["biglb"].Columns["category_id"], ds.Tables["product"].Columns["category_id"]);
etw_p.DataSource = ds.Tables["biglb"].DefaultView;
etw_p.DataBind();
}
补充:.NET技术 , ASP.NET