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 -
<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: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>
</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>
</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>
</ItemTemplate>
</asp:TemplateField>
Codebehind -
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();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmdAdjust);
da.Fill(ds);
gvPieceDetails.DataSource = ds;
gvPieceDetails.DataBind();
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 -
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