Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have Created one main gridview as gvMainTest
and in its template field created subgridview (gvSubTest)
I have bind data to both Grid and sub gridview I have one textbox field which contain some values Now I want to update that values


on submit button when I Get values using foreach loop for entire sub gridview but i am getting values to textbox doubles

also I have javascript function to show hide sub gridview on image but when I Enter values on sub gridview and then hide sub gridview in that case I need that values of text box to insert into database

What I have tried:

Gridview code is as follows

<div class="row my-col" style="border: 1px solid #a0e3a2; margin: 10px 0px; padding: 5px 0px;" runat="server" id="subentrygriddiv">
                           <div class="col-md-12  grid-view-div" style="margin-top: 10px;">
                               <div class="table-responsive grid-container" style="padding-bottom: 20px; margin-left: 0px;">
                                   <%--<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid" DataKeyNames="Main_Test_Id" OnRowDataBound="OnRowDataBound">--%>
                                   <asp:GridView ID="gvMainTest" runat="server" AutoGenerateColumns="false" DataKeyNames="Main_Test_Id" OnRowDataBound="gvMainTest_RowDataBound " CssClass="table table-bordered" Style="margin: 0px" ShowHeaderWhenEmpty="true">
                                       <Columns>
                                           <asp:TemplateField ItemStyle-Width="50px" ItemStyle-HorizontalAlign="center">

                                               <ItemTemplate>
                                                   <asp:CheckBox ID="CheckMain" runat="server" />
                                                   <%--<img alt="" style="cursor: pointer" src="Images/zoom_out.png" />--%>


                                                   </ItemTemplate>
                                               </asp:TemplateField>
                                           <asp:TemplateField ItemStyle-Width="50px" ItemStyle-HorizontalAlign="center">

                                               <ItemTemplate>
                                                       <img alt="" style="cursor: pointer" src="images/zoom_out.png" />

                                                   <%-- <asp:Panel ID="pnlOrders" runat="server" Style="display: none">--%>

                                                   <asp:Panel ID="pnlSubTest" runat="server" Style="display: none">
                                                       <asp:GridView ID="gvSubTest" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered" OnRowDataBound="gvSubTest_RowDataBound" >
                                                           <%-- <asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">--%>
                                                           <Columns>

                                                               <asp:TemplateField>
                                                                   <ItemTemplate>
                                                                       <asp:CheckBox ID="checkSub" runat="server" />
                                                                   </ItemTemplate>
                                                               </asp:TemplateField>

                                                               <asp:BoundField ItemStyle-Width="150px" DataField="Parameters_Id" HeaderText="Parameters Id" HeaderStyle-CssClass="hide" ItemStyle-CssClass="hidden" />
                                                               <asp:BoundField ItemStyle-Width="150px" DataField="Main_Test_Id" HeaderText="Main Test Id" HeaderStyle-CssClass="hide" ItemStyle-CssClass="hidden" />
                                                               <asp:BoundField ItemStyle-Width="400px" DataField="Parameter_Name" HeaderText="Parameter Name" />

                                                              <%-- <asp:BoundField ItemStyle-Width="200px" DataField="Result_Val" HeaderText="Site | Customer | General" />
                                                               <asp:BoundField ItemStyle-Width="100px" DataField="Result_Val" HeaderText="Min | Max" />--%>

                                                                <asp:BoundField ItemStyle-Width="200px" DataField="CustSiteGeneralRateSub" HeaderText="Site | Customer | General" />
                                                               <asp:BoundField ItemStyle-Width="100px" DataField="MinMaxSub" HeaderText="Min | Max" />
                                                               <asp:TemplateField>
                                                                   <HeaderTemplate>
                                                                       Rate:
                                                                   </HeaderTemplate>
                                                                   <ItemTemplate>
                                                                       <%--<asp:TextBox ID="txtSubRate" EnableViewState="false" runat="server" Style="height: auto; padding-bottom: 0px; margin: 0px;"  OnTextChanged="txtSubRate_TextChanged" OnLoad="txtSubRate_Load" AutoPostBack="true"/>--%>
                                                                       <asp:TextBox ID="txtSubRate" runat="server" Style="height: auto; padding-bottom: 0px; margin: 0px;" Text='<%# Eval("Rate") %>' />
                                                                   </ItemTemplate>
                                                               </asp:TemplateField>

                                                               <%--<asp:TemplateField>
                                                                   <ItemTemplate>
                                                                       <asp:TextBox ID="Value" runat="server" Style="height: auto; padding-bottom: 0px; margin: 0px;" />
                                                                   </ItemTemplate>
                                                               </asp:TemplateField>--%>
                                                           </Columns>
                                                       </asp:GridView>
                                                   </asp:Panel>
                                               </ItemTemplate>
                                           </asp:TemplateField>
                                           <asp:BoundField ItemStyle-Width="50px" DataField="Main_Test_Id" HeaderText="Main_Test_Id" HeaderStyle-CssClass="hide" ItemStyle-CssClass="hidden" />
                                           <asp:BoundField ItemStyle-Width="500px" DataField="Main_Test_Name" HeaderText="Main Test Name" />
                                           <asp:BoundField ItemStyle-Width="100px" DataField="Department_name" HeaderText="Department Name" />
                                           <asp:BoundField ItemStyle-Width="200px" DataField="CustSiteGeneralRate" HeaderText="Site | Customer | General" />
                                           <asp:BoundField ItemStyle-Width="100px" DataField="MinMax" HeaderText="Min | Max" />


                                           <asp:TemplateField>
                                               <HeaderTemplate>
                                                   Rate:
                                               </HeaderTemplate>
                                               <ItemTemplate>
                                                   <asp:TextBox ID="txtRate" runat="server" Style="height: auto; padding-bottom: 0px; margin: 0px;" Text='<%# Eval("Rate") %>' />
                                               </ItemTemplate>
                                           </asp:TemplateField>

                                           <asp:TemplateField>
                                               <HeaderTemplate>
                                                   Is Group:
                                               </HeaderTemplate>
                                               <ItemTemplate>
                                                   <asp:CheckBox ID="IsGroup" runat="server" Checked="true" OnCheckedChanged="IsGroup_CheckedChanged" />
                                               </ItemTemplate>
                                           </asp:TemplateField>

                                       </Columns>
                                   </asp:GridView>

                               </div>
                           </div>

                       </div>
                       <div class="row  my-col-btn">
                           <div class="col-md-12">
                               <asp:LinkButton runat="server" ID="btnSubmit" ValidationGroup="val" CssClass="btn btn-success" OnClick="btnSubmit_Click">Submit</asp:LinkButton>
                               <asp:LinkButton runat="server" ID="btnUpdate" ValidationGroup="val" CssClass="btn btn-success" OnClick="btnUpdate_Click">Update</asp:LinkButton>
                               <asp:LinkButton runat="server" ID="btnReset" CssClass="btn btn-danger" OnClick="btnReset_Click">Reset</asp:LinkButton>
                           </div>
                       </div>




javascript function

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

  <script type="text/javascript">
      $("[src*=zoom_out]").live("click", function () {
          //alert("Zoom In");
          $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
          $(this).attr("src", "images/zoom_in.png");
      });
      $("[src*=zoom_in]").live("click", function () {
          //alert("Zoom Out");
          //alert("Test2");
          $(this).attr("src", "images/zoom_out.png");
          $(this).closest("tr").next().remove();
      });
  </script>


btn submit code is as follows

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int customerId = 0;
        int SiteDetailsId = 0;
        int RefFromPickUPReqest = 0;
        int.TryParse(ddlCustomer.SelectedValue, out customerId);
        int.TryParse(ddlSite.SelectedValue, out SiteDetailsId);
        int.TryParse(ddlRefFromPickUPReqest.SelectedValue, out  RefFromPickUPReqest);
        Performa_invoice objPerforma_invoice = new Performa_invoice(-1, customerId, RefFromPickUPReqest, SiteDetailsId, DateTime.Now, EmpId);
        if (objPerforma_invoice.Insert())
        {
            int PerformanceId = 0;
            PerformanceId = objPerforma_invoice.GetMaxId();
            int MainTestId = 0;

            string checkBoxval = "";

            foreach (GridViewRow dr in gvMainTest.Rows)
            {
                CheckBox CheckMain = dr.FindControl("CheckMain") as CheckBox;
                if (CheckMain.Checked == true)
                {
                    int.TryParse(dr.Cells[1].Text, out MainTestId);
                    CheckBox chkItem = (CheckBox)dr.FindControl("IsGroup");
                    if (chkItem.Checked)
                    {
                        checkBoxval = "Yes";
                    }
                    else
                    {
                        checkBoxval = "No";
                    }


                    TextBox txtRate = (dr.Cells[6].FindControl("txtRate") as TextBox);
                    //TextBox txtRate = (TextBox)Page.FindControl("txtRate");

                    Pi_main_test objpi_main_test = new Pi_main_test(-1, PerformanceId, MainTestId, dr.Cells[4].Text, dr.Cells[5].Text, txtRate.Text, checkBoxval);
                    //Pi_main_test objpi_main_test = new Pi_main_test(-1, PerformanceId, MainTestId, dr.Cells[4].Text, dr.Cells[5].Text, dr.Cells[6].Text, checkBoxval);
                    objpi_main_test.Insert();
                    int PI_MT_ID = 0, ParameterId = 0;
                    PI_MT_ID = objpi_main_test.GetMaxId();
                    GridView gvSubTest = dr.FindControl("gvSubTest") as GridView;
                    foreach (GridViewRow dr2 in gvSubTest.Rows)
                        {
                        int.TryParse(dr2.Cells[1].Text, out ParameterId);
                        CheckBox checkSub = dr2.FindControl("checkSub") as CheckBox;
                        if (checkSub.Checked == true)
                        {
                            TextBox txtparameterRate12 = (dr2.Cells[6].FindControl("txtSubRate") as TextBox);

                            TextBox txtparameterRate22 = dr2.FindControl("txtSubRate") as TextBox;
                            //txtparameterRate12.
                                Pi_sub_test objPi_sub_test = new Pi_sub_test(-1, PI_MT_ID, MainTestId, ParameterId, dr2.Cells[4].Text, dr2.Cells[5].Text, txtparameterRate22.Text);
                            //Pi_sub_test objPi_sub_test = new Pi_sub_test(-1, PI_MT_ID, MainTestId, ParameterId, dr2.Cells[4].Text, dr2.Cells[5].Text, dr2.Cells[6].Text);
                            objPi_sub_test.Insert();
                        }
                    }

                }

            }

            AlertMesg(true, "Record insert successfully.");
            Reset();
            PanelShowHide();
            LoadGridView(1);
            LoadDrowpDown();
        }
        else
        {
            AlertMesg(false, "Record insertion fail. Please try again...!");
        }

    }
Posted
Comments
Vincent Maverick Durano 5-Dec-18 19:43pm    
I don't understand your question. You said you were already getting the values of TextBox in sub gridview and you were getting doubles. What does that suppose to mean?

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