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.Show Hide Button if Table has Row using C# in ASP.Net<p>I found the answer</p> <p>Check the below code:</p> <pre class="brush: csharp"> &lt;div style=&#34;scrollbar-highlight-color:aqua&#34; onscroll=&#34;true&#34;&gt; &lt;table align=&#34;center&#34; style=&#34;position: relative; top: 20px;margin-left:35%;border-style:double;align-content:center&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;table align=&#34;center&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Company Name&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;cname&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;City:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:DropDownList ID=&#34;city&#34; runat=&#34;server&#34; class=&#34;form-control input-lg&#34;&gt; &lt;asp:ListItem&gt;--Select City--&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Anand&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Surat&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Ahmedabad&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Gandhinagar&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Rajkot&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Jamnagar&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Phone no.:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_no&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Contact Person:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_Contact&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Address:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_address&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Email:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_mail&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt; &lt;asp:Button ID=&#34;btnsave&#34; runat=&#34;server&#34; Text=&#34;Save&#34; OnClick=&#34;btnsave_Click&#34; CssClass=&#34;btn btn-info&#34; /&gt; &lt;asp:Button ID=&#34;btnUpdate&#34; runat=&#34;server&#34; Text=&#34;Update&#34; OnClick=&#34;btnUpdate_Click&#34; CssClass=&#34;btn btn-info&#34; Visible=&#34;false&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align=&#34;center&#34;&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;lblMessage&#34; runat=&#34;server&#34; EnableViewState=&#34;false&#34; ForeColor=&#34;Blue&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type=&#34;hidden&#34; runat=&#34;server&#34; id=&#34;Id&#34; /&gt; &lt;/div&gt;</pre> <p>&nbsp;</p> <pre class="brush: csharp"> public partial class Company_profile : System.Web.UI.Page { SqlConnection mycon = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;Q_SS_regnConnectionString1&#34;].ToString()); SqlCommand cmd = new SqlCommand(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { mycon.Open(); cmd.Connection = mycon; cmd.CommandType = CommandType.Text; cmd.CommandText = &#34;Select Name,email from Common_regn2 where email=&#39;&#34; + Session[&#34;mail&#34;].ToString() + &#34;&#39;&#34;; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { cname.Text = dr[&#34;Name&#34;].ToString(); cname.ReadOnly = true; txt_mail.Text = dr[&#34;email&#34;].ToString(); txt_mail.ReadOnly = true; } } Session[&#34;name&#34;] = cname.Text.ToString(); } if (!IsPostBack) { mycon.Close(); mycon.Open(); cmd.Connection = mycon; cmd.CommandType = CommandType.Text; cmd.CommandText = &#34;Select City,phone,Contact_person,Address from Company_profile where email=&#39;&#34; + Session[&#34;mail&#34;].ToString() + &#34;&#39;&#34;; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { city.SelectedValue = dr[&#34;City&#34;].ToString(); txt_no.Text = dr[&#34;phone&#34;].ToString(); txt_Contact.Text = dr[&#34;Contact_person&#34;].ToString(); txt_address.Text = dr[&#34;Address&#34;].ToString(); btnsave.Visible = false; btnUpdate.Visible = true; } } } } protected void btnUpdate_Click(object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings[&#34;Q_SS_regnConnectionString1&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;UPDATE Company_profile SET Company_name=@Company_name,City=@City,phone=@phone,Contact_person=@Contact_person,Address=@Address WHERE email=&#39;&#34; + Session[&#34;mail&#34;].ToString() + &#34;&#39;&#34;, con); cmd.Parameters.AddWithValue(&#34;@Id&#34;, Id.Value); cmd.Parameters.AddWithValue(&#34;@Company_name&#34;, cname.Text); cmd.Parameters.AddWithValue(&#34;@City&#34;, city.SelectedValue.ToString()); cmd.Parameters.AddWithValue(&#34;@phone&#34;, txt_no.Text); cmd.Parameters.AddWithValue(&#34;@Contact_person&#34;, txt_Contact.Text); cmd.Parameters.AddWithValue(&#34;@Address&#34;, txt_address.Text); cmd.Parameters.AddWithValue(&#34;@email&#34;, txt_mail.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); lblMessage.Text = &#34;Updated Successfully.&#34;; } protected void btnsave_Click(object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings[&#34;Q_SS_regnConnectionString1&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;Insert into Company_profile (Company_name,City,phone,Contact_person,Address,email) Values (@Company_name,@City,@phone,@Contact_person,@Address,@email)&#34;, con); cmd.Parameters.AddWithValue(&#34;@Id&#34;, Id.Value); cmd.Parameters.AddWithValue(&#34;@Company_name&#34;, cname.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@City&#34;, city.SelectedValue.ToString()); cmd.Parameters.AddWithValue(&#34;@phone&#34;, txt_no.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@Contact_person&#34;, txt_Contact.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@Address&#34;, txt_address.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@email&#34;, txt_mail.Text.Trim().ToString()); con.Open(); cmd.ExecuteNonQuery(); con.Close(); lblMessage.Text = &#34;Saved Successfully.&#34;; } } </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/182669/Show-Hide-Button-if-Table-has-Row-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/182669/Show-Hide-Button-if-Table-has-Row-using-C-in-ASPNet/Sun, 04 Aug 2019 22:21:40 GMT