Skip to content
Loading
Insert data in database from dynamically generated textbox.  
  • class="container">  
  • class="responsive-table">  
  • class="table-row">  
  • class="col col-1" data-label="Job Id">Nozzle  
  • class="col col-2">  
  • "dataTable1" class="table-bordered table-hover table-striped table">  
  •   
  •   
  • "checkbox" name="chk" />  
  •   
  • "nozzle_lph" runat="server" type="text" placeholder="LPH">  
  •   
  • "nozzle_price" runat="server" type="text" placeholder="RS./unit">  
  •   
  •   
  •   
  • class="col col-3">  
  • class="col col-4">  
  • "button" class="btn btn-danger active" value="Add Row" onclick="addRow('dataTable1')" />  
  • "button" class="btn btn-info active" value="Delete Row" onclick="deleteRow('dataTable1')" />  
  •   
  •   
  •   
  •   
  • class="container">  
  • class="responsive-table">  
  • class="table-row">  
  • class="col col-1" data-label="Job Id">Lateral  
  • class="col col-2">  
  • "dataTable2" class="table-bordered table-hover table-striped table">  
  •   
  •   
  • "checkbox" name="chk" />  
  •   
  • "txt_lat_mm" runat="server" type="text" placeholder="LPH">  
  •   
  • "txt_lat_price" runat="server" type="text" placeholder="RS./unit">  
  •   
  •   
  •   
  • class="col col-3">  
  • class="col col-4">  
  • "button" class="btn btn-danger active" value="Add Row" onclick="addRow('dataTable2')" />  
  • "button" class="btn btn-info active" value="Delete Row" onclick="deleteRow('dataTable2')" />  
  •   
  •   
  •   
  •   
  • class="container">  
  • class="responsive-table">  
  • class="table-row">  
  • class="col col-1" data-label="Job Id">Submain Pipe  
  • class="col col-2">  
  • "dataTable3" class="table-bordered table-hover table-striped table">  
  •   
  •   
  • "checkbox" name="chk" />  
  •   
  • "txt_smain_mm" runat="server" type="text" placeholder="LPH">  
  •   
  • "txt_smain_price" runat="server" type="text" placeholder="RS./unit">  
  •   
  •   
  •   
  • class="col col-3">  
  • class="col col-4">  
  • "button" class="btn btn-danger active" value="Add Row" onclick="addRow('dataTable3')" />  
  • "button" class="btn btn-info active" value="Delete Row" onclick="deleteRow('dataTable3')" />  
  •   
  •   
  •   
  •   
  • class="container">  
  • class="responsive-table">  
  • class="table-row">  
  • class="col col-1" data-label="Job Id">Main Pipe  
  • class="col col-2">  
  • "dataTable4" class="table-bordered table-hover table-striped table">  
  •   
  •   
  • "checkbox" name="chk" />  
  •   
  • "txt_main_mm" runat="server" type="text" placeholder="LPH">  
  •   
  • "txt_main_price" runat="server" type="text" placeholder="RS./unit">  
  •   
  •   
  •   
  • class="col col-3">  
  • class="col col-4">  
  • "button" class="btn btn-danger active" value="Add Row" onclick="addRow('dataTable4')" />  
  • "button" class="btn btn-info active" value="Delete Row" onclick="deleteRow('dataTable4')" />  
  •   
  •   
  •   
  •   
  • class="container">  
  • class="responsive-table">  
  • class="table-row">  
  • class="col col-1" data-label="Job Id">Motor Pumping Unit  
  • class="col col-2">  
  • "dataTable5" class="table-bordered table-hover table-striped table">  
  •   
  •   
  • "checkbox" name="chk" />  
  •   
  • "txt_mpum_hp" runat="server" type="text" placeholder="LPH">  
  •   
  • "txt_mpump_price" runat="server" type="text" placeholder="RS./unit">  
  •   
  •   
  •   
  • class="col col-3">  
  • class="col col-4">  
  • "button" class="btn btn-danger active" value="Add Row" onclick="addRow('dataTable5')" />  
  • "button" class="btn btn-info active" value="Delete Row" onclick="deleteRow('dataTable5')" />  
  •   
  •   
  • class="table-row">  
  • class="col col-1" data-label="Job Id">  
  • class="col col-2" data-label="Customer Name">  
  • "sprink_submit" runat="server" CssClass="btn btn-danger btn-group-lg active" Text="Submit" OnClick="sprink_submit_Click" />  
  •   
  • class="col col-3" data-label="Amount">  
  • "Button2" runat="server" CssClass="btn btn-warning btn-group-lg active" Text="Back" />  
  •   
  •   
  •   
  •   
  •   
  •   
  • .aspx.cs
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Web;  
    5. using System.Web.UI;  
    6. using System.Web.UI.WebControls;  
    7. using System.Data;  
    8. using System.Data.SqlClient;  
    9. using System.Configuration;  
    10. using System.IO;  
    11. using System.Web.Script.Serialization;  
    12. namespace Test_captcha  
    13. {  
    14. public partial class test_table_dynamic : System.Web.UI.Page  
    15. {  
    16. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mycon"].ToString());  
    17. protected string Values;  
    18. protected void Page_Load(object sender, EventArgs e)  
    19. {  
    20. //c_email.Text = Session["Company"] as string;  
    21. }  
    22. protected void sprink_submit_Click(object sender, EventArgs e)  
    23. {  
    24. SqlCommand cmd = new SqlCommand("insert into company_sprinkler_data_test(company_email,nozzle_lph,noozle_price,lateral_mm,lateral_price,main_mm,main_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@Sp_mpump_hp,@Sp_mpump_price)");  
    25. con.Open();  
    26. cmd.Connection = con;  
    27. cmd.CommandType = CommandType.Text;  
    28. cmd.Parameters.AddWithValue("@company_email", c_email.Text.Trim().ToString());  
    29. cmd.Parameters.AddWithValue("@nozzle_lph", nozzle_lph.Text.Trim().ToString());  
    30. cmd.Parameters.AddWithValue("@nozzle_price", nozzle_price.Text.Trim().ToString());  
    31. cmd.Parameters.AddWithValue("@lateral_mm", txt_lat_mm.Text.Trim().ToString());  
    32. cmd.Parameters.AddWithValue("@lateral_price", txt_lat_price.Text.Trim().ToString());  
    33. cmd.Parameters.AddWithValue("@submain_mm", txt_smain_mm.Text.Trim().ToString());  
    34. cmd.Parameters.AddWithValue("@submain_price", txt_smain_price.Text.Trim().ToString());  
    35. cmd.Parameters.AddWithValue("@main_mm", txt_main_mm.Text.Trim().ToString());  
    36. cmd.Parameters.AddWithValue("@main_price", txt_main_price.Text.Trim().ToString());  
    37. cmd.Parameters.AddWithValue("@Sp_mpump_hp", txt_mpum_hp.Text.Trim().ToString());  
    38. cmd.Parameters.AddWithValue("@Sp_mpump_price", txt_mpump_price.Text.Trim().ToString());  
    39. int row;  
    40. try  
    41. {  
    42. row = cmd.ExecuteNonQuery();  
    43. if (row > 0)  
    44. {  
    45. ScriptManager.RegisterStartupScript(this, GetType(), "alert""alert('Price added Sucessful');window.location='MIS_login.aspx';"true);  
    46. }  
    47. else  
    48. {  
    49. ScriptManager.RegisterStartupScript(this, GetType(), "alert""alert('Add Prices again');"true);  
    50. }  
    51. }  
    52. catch (Exception)  
    53. {  
    54. throw;  
    55. }  
    56. finally  
    57. {  
    58. if (con.State == ConnectionState.Open)  
    59. con.Close();  
    60. }  
    61. }  
    62. }  
    63. }  
    Data table
    1. CREATE TABLE [dbo].[company_sprinkler_data_test] (  
    2. [sprink_id] INT IDENTITY (1, 1) NOT NULL,  
    3. [company_email] VARCHAR (100) NULL,  
    4. [nozzle_lph] INT NULL,  
    5. [noozle_price] FLOAT (53) NULL,  
    6. [lateral_mm] INT NULL,  
    7. [lateral_price] FLOAT (53) NULL,  
    8. [main_mm] INT NULL,  
    9. [main_price] FLOAT (53) NULL,  
    10. [Sp_mpump_hp] INT NULL,  
    11. [Sp_mpump_price] FLOAT (53) NULL,  
    12. PRIMARY KEY CLUSTERED ([sprink_id] ASC)  
    13. );  

    3 Replies

    Know the answer? Post it — somebody with the same question will find it here.