Asp.net,嵌套网格 [英] Asp.net, Nested Grid

查看:67
本文介绍了Asp.net,嵌套网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个gridiview,称为父Gridview,在父下还有一个gridview,称为子Gridview.在父" Gridview下,我有一个名为展开/折叠"的图像按钮.如果我单击展开",则对应的行将展开并显示intter gridview.假设我没有打开更多的内部网格视图,现在我想一次关闭所有内部网格视图.通过在父gridview标头使用一个图像对接.请给我脚本想法,一次折叠所有内部gridview.谁能帮我.

gridview代码

对不起,英语,谢谢.

穆西

Hi all, I have a gridiview, called parent gridview, under parent one more gridview is there called as child Gridview. Under Parent gridview I have an image button called Expand/Collapse. If i click on Expand the corresponding row will expand and show the innter gridview. Suppose i open more no of inner grid''s, now i want to close all the inner gridviews at a time. By using one image buttion at parent gridview header. Plz give me script idea to collapse all inner gridviews at a time. Can any body help me.

The gridview code

Sorry for the English, thanks in advance

Murthy

<asp:GridView ID="grvRecords" runat="server" AutoGenerateColumns="false" Font-Bold="True"

                                    Font-Names="Trebuchet MS" Font-Size="10px" AllowPaging="True" Font-Underline="False"

                                    OnRowCommand="grvRecords_RowCommand" OnPageIndexChanging="grvRecords_PageIndexChanging"

                                    AllowSorting="True" OnSorting="grvRecords_Sorting" PageSize="10"                                     OnRowDataBound="grvRecords_RowDataBound" Width="98%" >
                                    <columns>
                                    <asp:TemplateField>
                                            <HeaderTemplate>
                                                <input id="chkAllItems" type="checkbox"  önclick="CheckAllDataGridCheckBoxes('chkItemChecked',document.forms[0].chkAllItems.checked)"

                                                    value="Check">
                                            </HeaderTemplate>
                                            <itemtemplate>
                                                <asp:CheckBox ID="chkBulk" runat="server" Width="30px" AutoPostBack="False">
                                            </itemtemplate>
                                        
                                       <asp:TemplateField ItemStyle-Width="20px">
                                            <itemtemplate>
                                                <asp:Image runat="server" ID="img1" ImageUrl="images/Expand.GIF" />
                                            </itemtemplate>
                                        
                                        
                                        
                                        <asp:TemplateField Visible="false">
                                            <itemtemplate>
                                                <asp:Label ID="lblCodingId" runat="server" Text='<%#Eval("iCodingId") %>'>
                                            </itemtemplate>
                                        
                                                                                <asp:BoundField DataField="UploadDate" HeaderText="UploadDate" SortExpression="UploadDate" />
                                        <asp:BoundField DataField="vcRequest" HeaderText="Request" />
                                        <asp:BoundField DataField="vcStudentName" HeaderText="PName" />
                                                                                <asp:BoundField DataField="DOB" HeaderText="DOB" />
                                        <asp:BoundField DataField="DOJ" HeaderText="JOin.Date" />
                                        <asp:BoundField DataField="Course" HeaderText="Course" />
                                        <asp:TemplateField HeaderText="Category">
                                            <itemtemplate>
                                                <asp:Label ID="lblCategory" runat="server" Text='<%# Eval("Category")%>'>
                                                <asp:Literal runat="server" ID="lit1" Text="<tr id="trCollapseGrid" style="display:none"><td colspan="2"><td colspan="8" align="right">" />
                                                <asp:GridView ID="gvChild" AutoGenerateColumns="False" runat="server" EnableViewState="False" Width="100%"

                                                    ForeColor="#006666" HeaderStyle-HorizontalAlign="Center"  >
                                                    <rowstyle backcolor="#EFF3FB" />
                                                    <alternatingrowstyle backcolor="#EFF3FB" />
                                                    <columns>
                                                                                             <itemtemplate>
                                                        <asp:LinkButton ID="lnk1" runat ="server" Text='<%#Eval("RegNo") %>' CommandName="RegNo" CommandArgument='<%#Eval("RegNo") %>' >
                                                        </itemtemplate>
                                                        --%>
                                                        <asp:BoundField DataField ="vcCPT" HeaderText ="CPT" ItemStyle-HorizontalAlign="Center" />
                                                        <asp:BoundField HeaderText="Address1" DataField="Address1" ItemStyle-HorizontalAlign="Center" >
                                                        
                                                        <asp:BoundField HeaderText="Address2" DataField="Address2" ItemStyle-HorizontalAlign="Center" >
                                                        
                                                        <asp:BoundField HeaderText="Phone1" DataField="Phone1" ItemStyle-HorizontalAlign="Center" >
                                                        
                                                        <asp:BoundField HeaderText="Phone2" DataField="Phone2" ItemStyle-HorizontalAlign="Center" >
                                                        
                                                       <HeaderText="Remarks" DataField="vcRemarks" ItemStyle-HorizontalAlign="Center"  >
                                                        
                                                    </columns>
                                                    <HeaderStyle BackColor="#82c0ff" Font-Bold="True" ForeColor="White" />
                                                
                                                <asp:Literal runat="server" ID="lit2" Text="</td></td></tr>" />
                                            </itemtemplate>
                                        
                                    </columns>
                                    <HeaderStyle Font-Bold="True" Font-Underline="False" ForeColor="#0033CC" BackColor="#6699FF"

                                        Font-Names="Trebuchet MS" Font-Size="12px" />



C#代码



C# code

protected void grvRecords_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
        if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataTable dtChildTable = BindChildGridview();
                DataTable dtCloneChildTable = dtChildTable.Clone();
                //Image img = (Image)e.Row.Cells[1].FindControl("img1");
                Image img = (Image)e.Row.FindControl("img1");
                Literal ltrl = (Literal)e.Row.FindControl("lit1");
                ltrl.Text = ltrl.Text.Replace("trCollapseGrid", "trCollapseGrid" + e.Row.RowIndex.ToString());
                string str = "trCollapseGrid" + e.Row.RowIndex.ToString();
                e.Row.Cells[1].Attributes.Add("OnClick", "OpenGridTable('" + str + "','" + img.ClientID + "')");
                e.Row.Cells[1].RowSpan = 1;
                System.Web.UI.WebControls.GridView gvChild = (System.Web.UI.WebControls.GridView)e.Row.FindControl("gvChild");
                Label lbliPatId = (System.Web.UI.WebControls.Label)e.Row.FindControl("lbliPatientId");
                //DataRow[] gvChildRows = dtChildTable.Select("iPatientId = " + e.Row.Cells[0].Text);
                DataRow[] gvChildRows = dtChildTable.Select("iPatientId = " + Convert.ToInt32(lbliPatId.Text));
                foreach (DataRow gvChildRow in gvChildRows)
                {
                    dtCloneChildTable.ImportRow(gvChildRow);
                }
                gvChild.DataSource = dtCloneChildTable;
                gvChild.DataBind();
            }
        }


扩展单个内部gridview的脚本


Script for Expand individual inner gridview

<script language="javascript" type="text/javascript">
        //debugger;
        function OpenGridTable(trRow, imgId) {
            object = document.getElementById(trRow);
            if (object.style.display == "none") {
                object.style.display = "";
                document.getElementById(imgId).src = "Images/Collapse.gif";
            }
            else {
                object.style.display = "none";
                document.getElementById(imgId).src = "Images/Expand.gif";
            }
        }
    </script>

推荐答案


将命令名称设置为父gridview标题处的按钮,名称为"CollapsAll".处理"CollapsAll"命令的方法如下:
Hi,
Set the command name to the buttion at parent gridview header as "CollapsAll". Handle "CollapsAll" command as follows:
protected void gvEmpDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "CollapsAll")
        {
            fnCollapsAll();
        }
    }


现在在fnCollapsAll中,将所有子网格视图数据源设置为null,如下所示:


Now in fnCollapsAll set the all child grid-view data source to null as follows:

private void fnCollapsAll(){
    foreach(DataRow row in grvRecords.Rows){
          GridView gv=(GridView)row.FindControl("gvChild");
          gv.DataSource=null;
          gv.DataBind();
          //If you don't want to set the datasource as null just make it 
          //gv.Visible = false;
    }
}



祝一切顺利.
--Amit



All the best.
--Amit


这篇关于Asp.net,嵌套网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆