ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.[Solved] Dynamic TextBox value inserted zero in database using C# in ASP.Net<p>Hi <a class="username" rel="nid@patel"> nid@patel</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34;&gt; function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for (var i = 0; i &lt; colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; switch (newcell.childNodes[0].type) { case &#34;text&#34;: newcell.childNodes[0].value = &#34;&#34;; break; case &#34;checkbox&#34;: newcell.childNodes[0].checked = false; break; case &#34;select-one&#34;: newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for (var i = 0; i &lt; rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[1]; if (chkbox != null &amp;&amp; chkbox.checked == true) { if (rowCount &lt;= 1) { alert(&#34;Cannot delete all the rows.&#34;); break; } table.deleteRow(i); rowCount--; i--; } } } catch (e) { alert(e); } } &lt;/script&gt; &lt;div class=&#34;container&#34;&gt; &lt;h2&gt; Sprinkler Irrigation Component&#39;s price &lt;small&gt;&lt;/small&gt; &lt;/h2&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Email:&lt;/div&gt; &lt;div class=&#34;col col-2&#34; data-label=&#34;Customer Name&#34;&gt; &lt;asp:TextBox CssClass=&#34;form-control&#34; ID=&#34;c_email&#34; placeholder=&#34;Email&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34; data-label=&#34;Amount&#34;&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Nozzle&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable1&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;nozzle_lph&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;nozzle_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable1&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable1&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Lateral&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable2&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_lat_mm&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_lat_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable2&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable2&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Submain Pipe&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable3&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_smain_mm&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_smain_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable3&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable3&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Main Pipe&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable4&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_main_mm&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_main_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable4&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable4&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Motor Pumping Unit&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable5&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_mpum_hp&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_mpump_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable5&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable5&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-2&#34; data-label=&#34;Customer Name&#34;&gt; &lt;asp:Button ID=&#34;sprink_submit&#34; runat=&#34;server&#34; CssClass=&#34;btn btn-danger btn-group-lg active&#34; Text=&#34;Submit&#34; OnClick=&#34;sprink_submit_Click&#34; /&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34; data-label=&#34;Amount&#34;&gt; &lt;asp:Button ID=&#34;Button2&#34; runat=&#34;server&#34; CssClass=&#34;btn btn-warning btn-group-lg active&#34; Text=&#34;Back&#34; /&gt;&lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Configuration</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void sprink_submit_Click(object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings[&#34;Mycon&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;INSERT INTO test_sprink(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;, con); string[] textboxValues1 = Request.Form.GetValues(&#34;c_email&#34;); string[] textboxValues2 = Request.Form.GetValues(&#34;nozzle_lph&#34;); string[] textboxValues3 = Request.Form.GetValues(&#34;nozzle_price&#34;); string[] textboxValues4 = Request.Form.GetValues(&#34;txt_lat_mm&#34;); string[] textboxValues5 = Request.Form.GetValues(&#34;txt_lat_price&#34;); string[] textboxValues6 = Request.Form.GetValues(&#34;txt_smain_mm&#34;); string[] textboxValues7 = Request.Form.GetValues(&#34;txt_smain_price&#34;); string[] textboxValues8 = Request.Form.GetValues(&#34;txt_main_mm&#34;); string[] textboxValues9 = Request.Form.GetValues(&#34;txt_main_price&#34;); string[] textboxValues10 = Request.Form.GetValues(&#34;txt_mpum_hp&#34;); string[] textboxValues11 = Request.Form.GetValues(&#34;txt_mpump_price&#34;); int length = 0; if (textboxValues2.Length &gt; length) { length = textboxValues2.Length; } if (textboxValues3.Length &gt; length) { length = textboxValues3.Length; } if (textboxValues4.Length &gt; length) { length = textboxValues4.Length; } if (textboxValues5.Length &gt; length) { length = textboxValues5.Length; } if (textboxValues6.Length &gt; length) { length = textboxValues6.Length; } if (textboxValues7.Length &gt; length) { length = textboxValues7.Length; } if (textboxValues8.Length &gt; length) { length = textboxValues8.Length; } if (textboxValues9.Length &gt; length) { length = textboxValues9.Length; } if (textboxValues10.Length &gt; length) { length = textboxValues10.Length; } if (textboxValues11.Length &gt; length) { length = textboxValues11.Length; } for (int i = 0; i &lt; length; i++) { cmd = new SqlCommand(&#34;INSERT INTO test_sprink(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;, con); cmd.Parameters.AddWithValue(&#34;@company_email&#34;, textboxValues1[0]); cmd.Parameters.AddWithValue(&#34;@nozzle_lph&#34;, textboxValues2.Length &gt; i ? textboxValues2[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@nozzle_price&#34;, textboxValues3.Length &gt; i ? textboxValues3[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@lateral_mm&#34;, textboxValues4.Length &gt; i ? textboxValues4[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@lateral_price&#34;, textboxValues5.Length &gt; i ? textboxValues5[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@main_mm&#34;, textboxValues6.Length &gt; i ? textboxValues6[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@main_price&#34;, textboxValues7.Length &gt; i ? textboxValues7[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@submain_mm&#34;, textboxValues8.Length &gt; i ? textboxValues8[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@submain_price&#34;, textboxValues9.Length &gt; i ? textboxValues9[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@Sp_mpump_hp&#34;, textboxValues10.Length &gt; i ? textboxValues10[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@Sp_mpump_price&#34;, textboxValues11.Length &gt; i ? textboxValues11[i] : &#34;&#34;); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub sprink_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;Mycon&#34;).ConnectionString Dim con As SqlConnection = New SqlConnection(constr) Dim cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO test_sprink(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;, con) Dim textboxValues1 As String() = Request.Form.GetValues(&#34;c_email&#34;) Dim textboxValues2 As String() = Request.Form.GetValues(&#34;nozzle_lph&#34;) Dim textboxValues3 As String() = Request.Form.GetValues(&#34;nozzle_price&#34;) Dim textboxValues4 As String() = Request.Form.GetValues(&#34;txt_lat_mm&#34;) Dim textboxValues5 As String() = Request.Form.GetValues(&#34;txt_lat_price&#34;) Dim textboxValues6 As String() = Request.Form.GetValues(&#34;txt_smain_mm&#34;) Dim textboxValues7 As String() = Request.Form.GetValues(&#34;txt_smain_price&#34;) Dim textboxValues8 As String() = Request.Form.GetValues(&#34;txt_main_mm&#34;) Dim textboxValues9 As String() = Request.Form.GetValues(&#34;txt_main_price&#34;) Dim textboxValues10 As String() = Request.Form.GetValues(&#34;txt_mpum_hp&#34;) Dim textboxValues11 As String() = Request.Form.GetValues(&#34;txt_mpump_price&#34;) Dim length As Integer = 0 If textboxValues2.Length &gt; length Then length = textboxValues2.Length End If If textboxValues3.Length &gt; length Then length = textboxValues3.Length End If If textboxValues4.Length &gt; length Then length = textboxValues4.Length End If If textboxValues5.Length &gt; length Then length = textboxValues5.Length End If If textboxValues6.Length &gt; length Then length = textboxValues6.Length End If If textboxValues7.Length &gt; length Then length = textboxValues7.Length End If If textboxValues8.Length &gt; length Then length = textboxValues8.Length End If If textboxValues9.Length &gt; length Then length = textboxValues9.Length End If If textboxValues10.Length &gt; length Then length = textboxValues10.Length End If If textboxValues11.Length &gt; length Then length = textboxValues11.Length End If For i As Integer = 0 To length - 1 cmd = New SqlCommand(&#34;INSERT INTO test_sprink(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;, con) cmd.Parameters.AddWithValue(&#34;@company_email&#34;, textboxValues1(0)) cmd.Parameters.AddWithValue(&#34;@nozzle_lph&#34;, If(textboxValues2.Length &gt; i, textboxValues2(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@nozzle_price&#34;, If(textboxValues3.Length &gt; i, textboxValues3(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@lateral_mm&#34;, If(textboxValues4.Length &gt; i, textboxValues4(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@lateral_price&#34;, If(textboxValues5.Length &gt; i, textboxValues5(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@main_mm&#34;, If(textboxValues6.Length &gt; i, textboxValues6(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@main_price&#34;, If(textboxValues7.Length &gt; i, textboxValues7(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@submain_mm&#34;, If(textboxValues8.Length &gt; i, textboxValues8(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@submain_price&#34;, If(textboxValues9.Length &gt; i, textboxValues9(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@Sp_mpump_hp&#34;, If(textboxValues10.Length &gt; i, textboxValues10(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@Sp_mpump_price&#34;, If(textboxValues11.Length &gt; i, textboxValues11(i), &#34;&#34;)) con.Open() cmd.ExecuteNonQuery() con.Close() Next End Sub</pre>https://www.aspforums.net:443/Threads/481480/Solved-Dynamic-TextBox-value-inserted-zero-in-database-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/481480/Solved-Dynamic-TextBox-value-inserted-zero-in-database-using-C-in-ASPNet/Mon, 05 Aug 2019 03:33:53 GMT