当前位置:编程学习 > C#/ASP.NET >>

DataGrid如何实现这种效果?

  名称  数据一  数据二
+  A组  180    120
-  B组  180    100
   b1   180    100
   b2   180    100
+  C组  300    400


请问在datagrid中如何实践这种分级关系,如果没有子级就只显示一级,有子级的点加号显示子级内容。 --------------------编程问答-------------------- 嵌套的吧 --------------------编程问答-------------------- 用js控制行的现实隐藏 --------------------编程问答--------------------
引用 2 楼 oec2003 的回复:
用js控制行的现实隐藏

还没吃饭啊?
我还等着下班呢。 --------------------编程问答-------------------- 哈哈 --------------------编程问答-------------------- 这个有点复杂,好好想想、、、 --------------------编程问答-------------------- 夜深了,具体没去实现提供个思路:1、先用SQL语句分组,2、再用另一SQL语句(用名称做条件)获取具体分组信息,3、在datagrid中嵌套datagrid(Visible=false),根据点击+号获取该项记录的名称传入第二个SQL语句以做为条件,然后显示嵌套datagrid --------------------编程问答-------------------- Div+Css,嵌套一个datagrid --------------------编程问答-------------------- 脚本
 <script language=javascript type="text/javascript">
    function expandcollapse(obj,row)
    {
        var div = document.getElementById(obj);
        var img = document.getElementById('img' + obj);
        
        if (div.style.display == "none")
        {
            div.style.display = "block";
            if (row == 'alt')
            {
                img.src = "../Img/bg/minus.gif";
            }
            else
            {
                img.src = "../Img/bg/minus.gif";
            }
            img.alt = "隐藏";
        }
        else
        {
            div.style.display = "none";
            if (row == 'alt')
            {
                img.src = "../Img/bg/plus.gif";
            }
            else
            {
                img.src = "../Img/bg/plus.gif";
            }
            img.alt = "展开";
        }
    } 
    </script>

Gridview 代码

<asp:GridView ID="gvGoods" runat="server" ShowHeader="false" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"  Width="98%" OnRowDataBound="gvGoods_RowDataBound">                                                        <Columns>
                                                                                             <asp:TemplateField ItemStyle-HorizontalAlign="Left" ItemStyle-Width="5%">
                                                                                                <ItemTemplate>
                                                                                                    <a href="javascript:expandcollapse('div<%# Eval("ID") %>', 'one');">
                                                                                                        <img id="imgdiv<%# Eval("ID") %>" alt="Click to show/hide Orders for Customer <%# Eval("ID") %>"  width="9px" border="0" src="../Img/bg/plus.gif"/>
                                                                                                    </a>
                                                                                                </ItemTemplate>
                                                                                            </asp:TemplateField>
                                                                                            <asp:BoundField DataField="ID" />                                                                             <asp:TemplateField>                                                                                     <ItemTemplate>
                                                                                        <tr>
                                                                                                        <td colspan="100%" align="center">
                                                                                                            <div id="div<%# Eval("ID") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >
                                                                                                                <table width="100%" cellpadding="0" cellspacing="0" >
                                                                                                                    <tr>
                                                                                                                        <td rowspan="3" width="30%">
                                                                                                                            <asp:Image runat="server" ID="imgPic" Width="120px" BorderWidth="0" Height="120px" />
                                                                                                                        </td>
                                                                                                                        <td align="right" width="20%">收到的请求:   </td>
                                                                                                                        <td align="left">(5)</td>
                                                                                                                    </tr>
                                                                                                                    <tr>
                                                                                                                        <td align="right">被浏览次数:   </td>
                                                                                                                        <td align="left">(66)</td>
                                                                                                                    </tr>
                                                                                                                    <tr>
                                                                                                                        <td align="right">发布时间:   </td>
                                                                                                                        <td align="left">2009-04-05</td>
                                                                                                                    </tr>
                                                                                                                </table>
                                                                                                            </div>
                                                                                                        </td>
                                                                                                    </tr>
                                                                                                </ItemTemplate>
                                                                                            </asp:TemplateField>
                                                                                        </Columns>
                                                                                    </asp:GridView>

大概是怎样 --------------------编程问答-------------------- 代码有点乱。
脚本是在codeproject上找的 --------------------编程问答-------------------- 关注,想办法中 --------------------编程问答-------------------- 嵌套控件(DataItemBind事件)+Js隐藏 --------------------编程问答-------------------- 嵌套 --------------------编程问答-------------------- 说的都太笼统了 
但是我却没有实力帮你解决 --------------------编程问答-------------------- 嵌套 --------------------编程问答-------------------- 谢谢大家,有没有个Demo让我学习一下!
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,