如何嵌入的GridView GridView的另一个内 [英] How to Embed Gridview inside another Gridview

查看:100
本文介绍了如何嵌入的GridView GridView的另一个内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发包含嵌套的GridView(共3的GridView)的Web应用程序

I am Developing a web application which contains the Nested Gridview(totally 3 Gridview).

我的要求:
    我需要的是,根据在文本框中输入3 GridView的应该得到约束值。它应该陆续一旦显示如下

My Requirement: What I need is, Based on the value in the text box the 3 gridviews should get bound. and it should display Once after another as shown in the sample image below

我的问题是只有1格是有约束力的,但不是孩子grids.as如下图所示。

my problem is only the 1st grid is binding but not the child grids.as shown below.

下面是我的aspx code:

Here is my aspx code:

<asp:UpdatePanel ID="UPDestinationGrid" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="dgDestination1" runat="server" BorderWidth="1px" BorderColor="#FE9B00"
                            BorderStyle="Solid" BackColor="White" Font-Names="Verdana" Font-Size="XX-Small"
                            AutoGenerateColumns="False" ShowFooter="FALSE" CellPadding="3" align="center"
                            Width="700px" OnRowDataBound="dgDestination_OnRowDataBound"> 
                            <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
                            <SelectedRowStyle Font-Bold="True" ForeColor="Black" BackColor="Snow"></SelectedRowStyle>
                            <EditRowStyle BackColor="AntiqueWhite"></EditRowStyle>
                            <PagerStyle BackColor="#FDE9CB" ForeColor="#003399" HorizontalAlign="Right"
                                Font-Size="Small" Font-Bold="true" />
                            <AlternatingRowStyle BackColor="Snow"></AlternatingRowStyle>
                            <RowStyle ForeColor="#000066" BackColor="Snow"></RowStyle>
                            <HeaderStyle Font-Size="XX-Small" Font-Bold="True" Height="10px" ForeColor="#000000"
                            BackColor="#FFDBA6"></HeaderStyle>
            <Columns>
                <asp:TemplateField ItemStyle-Width="20px">
                <ItemTemplate>
                        <a href="JavaScript:divexpandcollapse('div<%# Eval("Port") %>');">
                            <img id="imgdiv<%# Eval("Port") %>" width="9px" border="0" 
                    </ItemTemplate>
                    <ItemStyle Width="20px" VerticalAlign="Middle"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Port">
                <ItemTemplate>
                    <asp:Label ID="lblPortID" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container.DataItem,
                                                                            "Port") %>'></asp:Label>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="mROU_NUPKId" HeaderText="mROU_NUPKId" Visible="False">
                </asp:BoundField>
                <asp:BoundField DataField="mROD_mROU_NUPKId" HeaderText="mROD_mROU_NUPKId" Visible="False">
                </asp:BoundField>
                <asp:BoundField DataField="Port" HeaderText="Ports"></asp:BoundField>
                <asp:TemplateField HeaderText="Sailing">
                    <ItemTemplate>
                        <tr>
                            <td colspan="100%">
                                <div id="div<%# Eval("Port") %>"  style="overflow:auto; display:none;
                                                        position: relative; left: 15px; overflow: auto">
                                    <asp:GridView ID="dgSailing" runat="server" BorderWidth="1px" BorderColor="#FE9B00"
                                                    BorderStyle="Solid" BackColor="White" Font-Names="Verdana" Font-Size="XX-Small"
                                                    AutoGenerateColumns="False" ShowFooter="FALSE" CellPadding="3" align="center"
                                                    Width="700px" DataKeyNames="Origin"
                                                    OnRowDataBound="dgSailing_OnRowDataBound">
                                                    <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
                                                    <SelectedRowStyle Font-Bold="True" ForeColor="Black" BackColor="Snow"></SelectedRowStyle>
                                                    <EditRowStyle BackColor="AntiqueWhite"></EditRowStyle>
                                                    <PagerStyle BackColor="#FDE9CB" ForeColor="#003399" HorizontalAlign="Right"
                                                    Font-Size="Small" Font-Bold="true" />
                                                    <AlternatingRowStyle BackColor="Snow"></AlternatingRowStyle>
                                                    <RowStyle ForeColor="#000066" BackColor="Snow"></RowStyle>
                                                    <HeaderStyle Font-Size="XX-Small" Font-Bold="True" Height="10px" ForeColor="#000000"
                                                    BackColor="#FFDBA6"></HeaderStyle>
                                        <Columns>
                                            <asp:TemplateField ItemStyle-Width="20px">
                                                <ItemTemplate>
                                                    <a href="JavaScript:divexpandcollapse('div1<%# Eval("ArrivalDate") %>');">
                                                    <img id="imgdiv1<%# Eval("ArrivalDate") %>" width="9px" border="0" src="AppImages/plus.gif"
                                                                alt="" /></a>                       
                                                </ItemTemplate>
                                                <ItemStyle Width="20px" VerticalAlign="Middle"></ItemStyle>
                                                </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Salary ID" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblArrivaldate" Visible="false" runat="server" Text='<%#DataBinder.Eval
                                                                                                (Container.DataItem, "ArrivalDate") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>

                                            <asp:BoundField DataField="Origin" HeaderText="Origin " SortExpression="Origin"></asp:BoundField>
                                            <asp:BoundField DataField="Destination" SortExpression="Destination" HeaderText="Destination"></asp:BoundField>
                                            <asp:BoundField DataField="ID" HeaderText="ID" Visible="False"></asp:BoundField>
                                            <asp:BoundField DataField="DepartureDate" HeaderText="Departure Date" SortExpression="DepartureDate" dataformatstring="{0:dd-MM-yyyy}"></asp:BoundField>
                                            <%--<asp:BoundField DataField="ArrivalDate" HeaderText="Arrival Date" SortExpression="ArrivalDate" dataformatstring="{0:dd-MM-yyyy}"></asp:BoundField>--%>
                                            <asp:BoundField DataField="Carrier" HeaderText="Carrier" SortExpression="Carrier"></asp:BoundField>
                                            <asp:BoundField DataField="VesselName" HeaderText="Vessel" SortExpression="VesselName"></asp:BoundField>
                                            <asp:BoundField DataField="VoyageNo" HeaderText="Voyage No" SortExpression="VoyageNo"></asp:BoundField>
                                            <asp:BoundField DataField="TransitTime" HeaderText="TransitTime" SortExpression="TransitTime"  DataFormatString="{0:n}"></asp:BoundField>
                                            <asp:BoundField DataField="DCFDate" HeaderText="DCF Date" SortExpression="DCFDate" dataformatstring="{0:dd-MM-yyyy}"></asp:BoundField>
                                            <asp:BoundField DataField="CCFDate" HeaderText="CCF Date" SortExpression="CCFDate" dataformatstring="{0:dd-MM-yyyy}"></asp:BoundField>
                                            <%-- <asp:TemplateField>
                                                <ItemTemplate>
                                                    <tr>
                                                        <td colspan="100%">
                                                            <div id="div1<%# Eval("ArrivalDate") %>"  style="overflow:auto; display:none;
                                                                                        position: relative; left: 15px; overflow: auto">
                                                                <asp:GridView ID="dgJobgrid" runat="server" BorderWidth="1px" BorderColor="#FE9B00"
                                                                                    BorderStyle="Solid" BackColor="White" Font-Names="Verdana" Font-Size="XX-Small"
                                                                                    AutoGenerateColumns="False" ShowFooter="FALSE" CellPadding="3" align="center"
                                                                                    Width="700px" OnRowDataBound="dgJobgrid_OnRowDataBound" >
                                                                                    <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
                                                                                    <SelectedRowStyle Font-Bold="True" ForeColor="Black" BackColor="Snow"></SelectedRowStyle>
                                                                                    <EditRowStyle BackColor="AntiqueWhite"></EditRowStyle>
                                                                                    <PagerStyle BackColor="#FDE9CB" ForeColor="#003399" HorizontalAlign="Right" Font-Size="Small" Font-Bold="true" />
                                                                                    <AlternatingRowStyle BackColor="Snow"></AlternatingRowStyle>
                                                                                    <RowStyle ForeColor="#000066" BackColor="Snow"></RowStyle>
                                                                                    <HeaderStyle Font-Size="XX-Small" Font-Bold="True" Height="10px" ForeColor="#000000"
                                                                                    BackColor="#FFDBA6"></HeaderStyle>


                                                                    <Columns>
                                                                    <asp:TemplateField HeaderText="SNO">
                                                                        <HeaderStyle Width="5%" Font-Underline="true" />
                                                                        <ItemTemplate>
                                                                                <%# Container.DataItemIndex + 1%>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:BoundField DataField="tBLG_NUPKId" HeaderText="tBLG_NUPKId" Visible="False"></asp:BoundField>
                                                                    <asp:BoundField DataField="PortOfLoadName" HeaderText="Origin"></asp:BoundField>
                                                                    <asp:BoundField DataField="MasterNo" HeaderText="JobNo"></asp:BoundField>
                                                                    <asp:BoundField DataField="Volume" HeaderText="Volume"></asp:BoundField>
                                                                    <asp:BoundField DataField="Volumetype" HeaderText="Volumetype"></asp:BoundField>
                                                                    </asp:GridView>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </ItemTemplate>
                                            </asp:TemplateField>--%>
                                        </Columns>
                                    </asp:GridView>
                                </div>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:TemplateField>    
            </Columns>
            <PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" >
            </PagerStyle>
        </asp:GridView>
    </contenttemplate>
</asp:UpdatePanel> 

这是的.cs code:

and this is .cs code:

private void BindDestinationgrid()
{
    try
    {
        UPDestinationGrid.Update();
        UPDestinationGrid.Update();
        if (PortLID.Text == "" || PortLID.Text == "0")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('Select The Loading Port');", true);
        }
        else if (PortDID.Text == "" || PortDID.Text == "0")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('Select The Destination Port');", true);
        }
        else if (TxtArrivalDate.Text=="")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('Select The ArrivalDate');", true);
        }

        if (PortLID.Text != "" && PortLID.Text != "0")
        {
            using (LQMasterRouteDetailDataContext DB = new LQMasterRouteDetailDataContext())
            {
                var Result = from C in DB.VW_MasterRoutes
                                where C.mROU_NUIsActive == 1 && C.Origin == PortLName.Text && C.Destination == PortDName.Text
                                select new { mROU_NUPKId = C.mROU_NUPKId, mROD_mROU_NUPKId = C.mROD_mROU_NUPKId,  Port = C.Port };
                dgDestination1.DataSource = Result;
                dgDestination1.DataBind();
                int Count = Result.Count();
                if (Count == 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('No Port found');", true);
                }
                //BindSailinggrid();
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('Please Select the Loading Port');", true);
        }
    }
    catch (Exception ex)
    {

    }
}

protected void dgDestination_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        UPDestinationGrid.Update();
        UpGeneralCondrols.Update();
        Label lblPortID = (Label)e.Row.FindControl("lblPortID");
        GridView dgSailing = (GridView)e.Row.FindControl("dgSailing");
        string txtempid = lblPortID.Text;
        if (TxtArrivalDate.Text == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('Please Select the Date');", true);
        }
        else if (TxtArrivalDate.Text != "" && PortLName.Text !="" && txtempid != "")
        {

            using (LQMasterSailingScheduleDataContext DB = new LQMasterSailingScheduleDataContext())
            {
                var Result = from C in DB.VW_MasterSailingScheduleViews
                                where C.mVSS_NUIsActive == 1 && C.ArrivalDate == mobjGenlib.Getdate(TxtArrivalDate.Text) && C.Origin == PortLName.Text && C.Destination ==txtempid
                                select new
                                {
                                    Origin = C.Origin,
                                    Destination = C.Destination,
                                    DepartureDate = C.DepartureDate,
                                    ArrivalDate = C.ArrivalDate,
                                    Carrier = C.Carrier,
                                    VesselName = C.VesselName,
                                    VoyageNo = C.VoyageNo,
                                    TransitTime = C.TransitTime,
                                    DCFDate = C.DCFDate,
                                    CCFDate = C.CCFDate,
                                    ID = C.mVSS_NUPKId
                                };

                dgSailing.DataSource = Result;
                dgSailing.DataBind();
                int Count = Result.Count();
                if (Count == 0)
                {
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('No Vessel found');", true);
                }
            }    
        }
    }
}

任何一个可以请帮助我。

can any one please help me.

推荐答案

以下链接帮助我上悬而未决我的问题

the following Link helps me to slove my issue

http://www.$c$cproject.com/Articles/777855/Nested-GridView-in-ASP-NET-using-Csharp

这篇关于如何嵌入的GridView GridView的另一个内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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