首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

GridView显示层级菜单()

2012-02-16 
GridView显示层级菜单(在线等)小弟想在GridView里把数据库里的类别菜单显示出来。但菜单包含大小类,如何按

GridView显示层级菜单(在线等)
小弟想在GridView里把数据库里的类别菜单显示出来。但菜单包含大小类,如何按大小类的层级关系显示出来,各位打侠帮帮忙,这个问题小弟我从昨天搞到现在没搞出来。

[解决办法]
GridView里嵌套GridView
<asp:GridView ID="gvFilmBase" runat="server" AutoGenerateColumns="False" Width="100%" OnRowDataBound="gvFilmBase_RowDataBound" AllowPaging="True" OnPageIndexChanging="gvFilmBase_PageIndexChanging" OnRowCreated="gvFilmBase_RowCreated" PageSize="13">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<table
borderColor="#ffffff" cellSpacing="0" cellPadding="0" width="100%" style="border-left-width: 1px; border-left-color: #ff99ff; border-top-style: none; border-right-width: 1px; border-right-color: #99ccff; border-bottom-style: none" border="0">
<tr>
<td align="center" width="3%" style="height: 30px">
</td>
<td align="center" width="7%" style="height: 30px">
编号</td>
<td align="center" width="15%" style="height: 30px">
类型</td>
<td align="center" width="35%" style="height: 30px">
影片名称</td>
<td align="center" width="25%" style="height: 30px">
加入时间</td>
<td align="center" width="15%" style="height: 30px">
作者</td>
</tr>
</table>

</HeaderTemplate>
<ItemTemplate>
<table style="width: 100%; border-top-style:none; border-bottom-style: none; border-top-color: #ffffff; border-collapse: collapse; border-left-width: 1px; border-left-color: #9933ff; border-right-width: 1px; border-right-color: #9900ff;">
<tr>
<td style="height: 20px" width="3%" align="center"><DIV style="CURSOR: hand" onclick="ShowDetail(this);">+</DIV>
</td>
<td style="height: 20px" width="7%" align="center">
<asp:Label ID="lbNum" runat="server" Text='<%# Eval("ID") %>'></asp:Label></td>
<td style="height: 20px; width: 15%;" align="center">
<asp:Label ID="lbSort" runat="server" Text='<%# Eval("Sort") %>'></asp:Label></td>
<td style="height: 20px" width="35%" align="center">


<asp:Label ID="lbName" runat="server" Text='<%# Eval("Topic") %>'></asp:Label></td>
<td style="height: 20px" width="25%" align="center">
<asp:Label ID="lbTime" runat="server" Text='<%# Eval("ToTime") %>'></asp:Label></td>
<td style="height: 20px" width="15%" align="center">
<asp:Label ID="lbAuthor" runat="server" Text='<%# Eval("Author") %>'></asp:Label></td>
</tr>
<tr style="display:none">
<td style="width: 3%; height: 17px;" bgcolor="#ffffff">
</td>
<td colspan="5" style="width: 97%; height: 17px;" bgcolor="#ffffff">
<asp:GridView ID="gvFilmDetails" runat="server" AutoGenerateColumns="False" Width="100%" DataSourceID="sqlGetFilmMatter">
<Columns>
<asp:TemplateField HeaderText="主演">
<ItemStyle Width="20%" />
<HeaderStyle Width="20%" HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lbRole" runat="server" Width="100%" Text='<%# Eval("Roles") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="内容介绍">
<ItemStyle Width="80%" />
<HeaderStyle Width="80%" HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lbMatter" runat="server" Width="100%" Text='<%# Eval("Matter") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlGetFilmMatter" runat="server" ConnectionString="<%$ ConnectionStrings:MovieConnectionString %>"></asp:SqlDataSource>
</td>

</tr>
</table>
</ItemTemplate>


</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Right" />
<PagerSettings Mode="NextPreviousFirstLast" />
</asp:GridView>




CS代码:
 protected void gvFilmBase_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int id;
Label lb = e.Row.FindControl("lbNum") as Label;
SqlDataSource sqlFilmDetails = e.Row.FindControl("sqlGetFilmMatter") as SqlDataSource;
id=Convert.ToInt32(lb.Text.ToString());
sqlFilmDetails.SelectCommand = "select Roles,Matter from myBlog where ID='" + id + "'";
}
}


这是关键部分,其他的自己写
[解决办法]
javascript代码:
 function ShowDetail(object)
{
table = object.parentElement.parentElement.parentElement;
if(table.rows(1).style.display == "none")
{
table.rows(1).style.display = "block";
object.innerText = "-"
}
else
{
table.rows(1).style.display = "none";
object.innerText = "+";
}
}

热点排行