Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void GridDataSave()
   {
       foreach (GridViewRow s in grdqutotation.Rows)
       {
           ////TextBox id = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_id");

           //TextBox srno = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_srno");

           //TextBox description = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_desc");

           //TextBox Quantity = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Qty");

           //TextBox Units = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Unit");

           //TextBox Rate = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Rate");

           //TextBox Amount = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_amount");
           Tbl_SubFinalQuotation a = new Tbl_SubFinalQuotation();
           ////  TextBox id = (TextBox)s.FindControl("txt_id");
           a.Quto_No = txtQno.Text;
           ////a.id = Convert.ToInt32(s.Cells[0].Text);
           TextBox srno = (TextBox)s.FindControl("txt_srno");
           //Decimal p = Convert.ToDecimal((srno.Text));
           TextBox description = (TextBox)s.FindControl("txt_desc");
          // string q = description.Text;
           TextBox Quantity = (TextBox)s.FindControl("txt_Qty");
           //Decimal r = Convert.ToDecimal((Quantity.Text));
           TextBox Units = (TextBox)s.FindControl("txt_Unit");
          // string t = Units.Text;
           TextBox Rate = (TextBox)s.FindControl("txt_Rate");
          // Decimal u = Convert.ToDecimal((Rate.Text));
           TextBox Amount = (TextBox)s.FindControl("txt_amount");
         //  Decimal v = Convert.ToDecimal((Amount.Text));

           a.srno = Convert.ToDecimal (srno.Text );
           a.productName = description .Text ;
           a.Quantity = Convert.ToDecimal (Quantity .Text );
           a.Units = Units .Text ;
           a.Rate = Convert.ToDecimal (Rate .Text );
           a.Amount = Convert.ToDecimal (Amount .Text );

           context.Tbl_SubFinalQuotations.InsertOnSubmit(a);
           context.SubmitChanges();
           a = null;
       }
   }


What I have tried:

C#
private void GridDataSave()
    {
        foreach (GridViewRow s in grdqutotation.Rows)
        {
            ////TextBox id = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_id");

            //TextBox srno = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_srno");

            //TextBox description = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_desc");

            //TextBox Quantity = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Qty");

            //TextBox Units = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Unit");

            //TextBox Rate = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Rate");

            //TextBox Amount = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_amount");
            Tbl_SubFinalQuotation a = new Tbl_SubFinalQuotation();
            ////  TextBox id = (TextBox)s.FindControl("txt_id");                   
            a.Quto_No = txtQno.Text;
            ////a.id = Convert.ToInt32(s.Cells[0].Text);
            TextBox srno = (TextBox)s.FindControl("txt_srno");
            //Decimal p = Convert.ToDecimal((srno.Text));
            TextBox description = (TextBox)s.FindControl("txt_desc");
           // string q = description.Text;
            TextBox Quantity = (TextBox)s.FindControl("txt_Qty");
            //Decimal r = Convert.ToDecimal((Quantity.Text));
            TextBox Units = (TextBox)s.FindControl("txt_Unit");
           // string t = Units.Text;
            TextBox Rate = (TextBox)s.FindControl("txt_Rate");
           // Decimal u = Convert.ToDecimal((Rate.Text));
            TextBox Amount = (TextBox)s.FindControl("txt_amount");
          //  Decimal v = Convert.ToDecimal((Amount.Text));

            a.srno = Convert.ToDecimal (srno.Text );
            a.productName = description .Text ;
            a.Quantity = Convert.ToDecimal (Quantity .Text );
            a.Units = Units .Text ;
            a.Rate = Convert.ToDecimal (Rate .Text );
            a.Amount = Convert.ToDecimal (Amount .Text );

            context.Tbl_SubFinalQuotations.InsertOnSubmit(a);
            context.SubmitChanges();
            a = null;
        }
    }
Posted
Updated 30-Aug-16 22:03pm
v2
Comments
avelsamy 31-Aug-16 6:47am    
some values are "NULL" while ur binding, make your result set shoud have values

1 solution

Run your code in the debugger, Visual Studio will stop on the offending line, move your mouse over the line and see in the tool tips which object is null.
 
Share this answer
 

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