Click here to Skip to main content
15,847,583 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using a nested grid which has a templated grid column.
- I am mentioning the 'AutoGeneratedColumn' as False.
- I have checked thoroughly nowhere the _RowDataBound is getting called twice.
- Neither the grid.BindData() is getting called twice.
- The dataset is showing the perfect data.
- Still the column is getting duplicated after the postback.
- First the grid is loaded with the value then after a pause it is been duplicated.

What I have tried:

Source -

ASP.NET
<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:ImageButton ID="imgPieceDetailsShow" runat="server" OnClick="Show_Hide_PieceDetailsGrid"
                ImageUrl="~/Images/plus.png" CommandArgument="Show" postbacktrigger="false" />
            <asp:Panel ID="pnlOrders" runat="server" Visible="false" Style="padding-top: 4px;">
                <asp:GridView ID="gvPieceDetails" runat="server" AutoGenerateColumns="false" AllowPaging="false"
                    CssClass="ChildGrid" OnRowDataBound="gvPieceDetails_RowDataBound">
                    <Columns>
                        <asp:TemplateField HeaderText="UniqueIdentifier" SortExpression="UNI" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label ID="lblUnique" runat="server" Text='<%# Bind("UNI") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField ItemStyle-Width="150px" DataField="ProcessedAmount" HeaderText="Processed Amount"
                            ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField ItemStyle-Width="150px" DataField="AppliedAmount" HeaderText="Applied Amount"
                            ItemStyle-HorizontalAlign="Center" />
                        <asp:TemplateField HeaderText="AdjustedAmount" SortExpression="AdjustedAmount" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label ID="lblAdjustedAmount" runat="server" Text='<%# Bind("Adjusted_Amount")%>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="AmountDifference" SortExpression="AmountDiff" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label ID="lblAmountdiff" runat="server" Text='<%# Bind("AmountDiff", "{0:c}") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <%--<asp:BoundField ItemStyle-Width="150px" DataField="UNI" HeaderText="UNI" ItemStyle-HorizontalAlign="Center"/> --%>
                        <asp:TemplateField HeaderText="Adjustment" SortExpression="Adjustment" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Button ID="btnPieceAdjust" runat="server" Text="Adj" OnClick='btnPieceAdjust_click'
                                    Style="height: 20px; width: 30px; font-family: Arial; font-size: 10px;" OnClientClick='doPop()' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField ItemStyle-Width="150px" DataField="Description" HeaderText="Description"
                            ItemStyle-HorizontalAlign="Center" />
                    </Columns>
                </asp:GridView>
            </asp:Panel>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Publisher" SortExpression="Publisher" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
            <asp:Label ID="lblPublisherDetails" runat="server" Text='<%# Bind("Publisher") %>'></asp:Label>&nbsp;
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Cage Date" SortExpression="TimePeriod">
        <ItemTemplate>
            <asp:Label ID="lblCageDateDetails" runat="server" Text='<%# Eval("CageDate", "{0:MM/dd/yy}") %>'></asp:Label>&nbsp;
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Batch Number" SortExpression="WipsBatchNum" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
            <asp:Label ID="lblWipsBatchNumDetails" runat="server" Text='<%# Bind("WipsBatchNum") %>'></asp:Label>&nbsp;
        </ItemTemplate>
    </asp:TemplateField>



Codebehind -

C#
private void BindPieceDetails(string Wips, string Cagedate, string Magcode, GridView gvPieceDetails)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProdConnectionStr_Rpt"].ConnectionString);

        SqlCommand cmdAdjust = new SqlCommand("GetReconbyPiece", conn);
        cmdAdjust.CommandType = CommandType.StoredProcedure;
        cmdAdjust.Parameters.Add(new SqlParameter("WipsBatchNum", SqlDbType.NVarChar, 20));
        cmdAdjust.Parameters["WipsBatchNum"].Value = Wips;
        cmdAdjust.Parameters.Add(new SqlParameter("CageDate", SqlDbType.DateTime, 20));
        cmdAdjust.Parameters["CageDate"].Value = Cagedate;
        cmdAdjust.Parameters.Add(new SqlParameter("MagCode", SqlDbType.NVarChar, 20));
        cmdAdjust.Parameters["MagCode"].Value = Magcode;
        try
        {
            conn.Open();
            //SqlDataReader drPieceRecon = cmdAdjust.ExecuteReader();
            //gvPieceDetails.DataSource = drPieceRecon;
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmdAdjust);
            da.Fill(ds);
            gvPieceDetails.DataSource = ds;

            //gvPieceDetails.DataSource = "ImageWorkflowDataSrc";
            //DataTable dataTable = (DataTable)gvPieceDetails.DataSource;

            gvPieceDetails.DataBind();
            //gvPieceDetails.Columns[6].Visible = false;

            UpdatePanelgrdRecon.Update();

            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>myFunction();</script>", false);
            ds.Dispose();
        }
        finally
        {
            conn.Close();          
        }      
    }


The result is coming like the following -

C#
	Publisher	Date	Batch	Amount	
+	a	1/1/2016	123	100	
UniqueID	Item	Amount			
1	x	50			
2	y	30			
3	z	20			
			UniqueID	Item	Amount
			1	x	50
			2	y	30
			3	z	20
	b	1/2/2016	123	65	
	c	1/3/2016	123	200	
	d	1/4/2016	123	309	
Posted

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