Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to display grid inside another grid but when i do this my master grid data comes well but the child grid data comes two times and i don't know how it is happening.

below is my gridview :

<asp:GridView runat="server" ID="GrdAmMaster" AutoGenerateColumns="False" CssClass="fontstyleGrd"
                        BackColor="White" BorderColor="LightGray" BorderStyle="Solid" BorderWidth="1px"
                        CellPadding="1" Width="900px" AllowPaging="True" DataKeyNames="SrNo" ShowHeader="false">
                        <HeaderStyle BackColor="Black" ForeColor="#fcbf04" />
                        <Columns>
                            <asp:TemplateField HeaderText="View">
                                <ItemStyle Width="30px" />
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbRmView" Text="View" CommandArgument='<% # Eval("SrNo")%>' CommandName="View"
                                        runat="server" CssClass="grdlink">
                                    </asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <%--<asp:TemplateField HeaderText="Sr.No.">
                                <ItemStyle Width="50px" HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <%#Container.DataItemIndex+1%>
                                </ItemTemplate>
                            </asp:TemplateField>--%>
                            <asp:BoundField HeaderText="Sr.No." DataField="SrNo" ItemStyle-Width="40px" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                            <asp:BoundField HeaderText="Activity Name" DataField="AmName" ItemStyle-Width="300px">
                                <ItemStyle Width="300px"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField HeaderText="UOM" DataField="AmUOM" ItemStyle-Width="200px"></asp:BoundField>
                            <asp:TemplateField HeaderText="ManPower" ItemStyle-Width="200px">
                                <ItemTemplate>
                                    <asp:Panel ID="pnlAmChild" runat="server">
                                        <asp:GridView ID="GrdAmMasterChild" runat="server" Width="400px" ShowHeader="false" BorderWidth="0px">
                                            <Columns>
                                                <asp:TemplateField HeaderText="Sr.No.">
                                                    <ItemStyle Width="30px" HorizontalAlign="Center" />
                                                    <ItemTemplate>
                                                        <%#Container.DataItemIndex+1%>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField HeaderText="Designation" DataField="AmDesig" ItemStyle-Width="170px"></asp:BoundField>
                                                <asp:BoundField HeaderText="Numbers" DataField="AmNumbers" ItemStyle-Width="100px"></asp:BoundField>
                                            </Columns>
                                        </asp:GridView>
                                    </asp:Panel>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle HorizontalAlign="Center" />
                        <RowStyle Width="100px" />
                    </asp:GridView>


and my code for display child and master grid data :
VB
Protected Sub BindAmMasterGrid()
        Try
            ObjCls.LoadGrid(GrdAmMaster, "SELECT Distinct SrNo, AmName, AmUOM FROM BOQActivityMasterMst WHERE EmpSrNo = '" & Session("ESrNo") & "'", "BOQActivityMasterMst")
        Catch ex As Exception

        End Try
    End Sub
    Protected Sub GrdAmMaster_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GrdAmMaster.RowDataBound
        Try
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim SrNoC As String = GrdAmMaster.DataKeys(e.Row.RowIndex).Value.ToString()
                Dim gvOrders As GridView = TryCast(e.Row.FindControl("GrdAmMasterChild"), GridView)
                ObjCls.LoadGrid(gvOrders, "SELECT Distinct SrNo, (select DesName from DesigMst where SrNo = AmDesig) as AmDesig, AmNumbers from BOQActivityMasterDet where RefSrNo = " & SrNoC & " and EmpSrNo = '" & Session("ESrNo") & "' Order By SrNo", "BOQActivityMasterDet")
            End If
        Catch ex As Exception

        End Try
    End Sub


below is the result what i get:

Dropbox - Grid.png[^]

What I have tried:

above is the code which i have tried but not get any perfect solution.
Posted
Updated 22-Mar-16 20:09pm
v2
Comments
Where are you calling the method BindAmMasterGrid?
ketan chandpa 23-Mar-16 2:20am    
on the page load event inside the page.ispost back code
<pre>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Not Page.IsPostBack Then
If Val(Session("ESrNo")) <= 0 Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "RelAm1", "ShowRelogin();", True)
Exit Sub
End If
ClearAllAm()
LoadCheckBoxRaw()
BindAmMasterGrid()
End If
Catch ex As Exception

End Try
End Sub
</pre>
ketan chandpa 23-Mar-16 3:11am    
thanks for comment and finally i got my solution for this.
i forgot to put auto generated columns to false in child grid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900