问题
I am Developing a web application which contains the Nested Gridview(totally 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
my problem is only the 1st grid is binding but not the child grids.as shown below.
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>
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.
回答1:
the following Link helps me to slove my issue
http://www.codeproject.com/Articles/777855/Nested-GridView-in-ASP-NET-using-Csharp
来源:https://stackoverflow.com/questions/25262907/how-to-embed-gridview-inside-another-gridview