ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.Show hide Label based on user status using C# in ASP.Net<p>Hi <a class="username" rel="micah"> micah</a>,</p> <p>Please explain in more details.</p>http://www.aspforums.net/Threads/954159/Show-hide-Label-based-on-user-status-using-C-in-ASPNet/http://www.aspforums.net/Threads/954159/Show-hide-Label-based-on-user-status-using-C-in-ASPNet/Wed, 02 Nov 2016 02:09:46 GMTShow hide Label based on user status using C# in ASP.Net<p>For example, if my name is James in User Account table like below</p> <p>Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UserName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status</p> <p>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; James&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; true</p> <p>2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; false</p> <p>&nbsp;</p> <p>the on datalist display i have image and Lable status</p> <p>&nbsp;</p> <p>&nbsp;</p> <pre class="brush: html"> &lt;asp:Label ID=&#34;Label1&#34; runat=&#34;server&#34; CssClass=&#34;fa fa-check-circle verified-color&#34; data-toggle=&#34;tooltip&#34; title=&#34;&#34; data-original-title=&#34;Verified Page&#34; &gt;&lt;/asp:Label&gt;</pre> <p>if James is true in account table show this lable above in datalist, if false hid lable</p>http://www.aspforums.net/Threads/954159/Show-hide-Label-based-on-user-status-using-C-in-ASPNet/http://www.aspforums.net/Threads/954159/Show-hide-Label-based-on-user-status-using-C-in-ASPNet/Thu, 03 Nov 2016 00:16:28 GMTShow hide Label based on user status using C# in ASP.Net<p>Hi <a class="username" rel="micah"> micah</a>,</p> <p>I have created sample code which fullfill your requirement.</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:TextBox ID=&#34;txtuserName&#34; runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Button ID=&#34;btnSubmit&#34; Text=&#34;Submit&#34; runat=&#34;server&#34; OnClick=&#34;Unnamed1_Click&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:DataList ID=&#34;dlStatus&#34; runat=&#34;server&#34; OnItemDataBound=&#34;dlStatus_ItemDataBound&#34;&gt; &lt;HeaderTemplate&gt; &lt;table&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblStatusName&#34; Visible=&#34;false&#34; Text=&#34;Status:&#34; runat=&#34;server&#34; /&gt; &lt;asp:Label ID=&#34;lblStatus&#34; Text=&#39;&lt;%#Eval(&#34;Status&#34;)%&gt;&#39; Visible=&#34;false&#34; runat=&#34;server&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:Image ID=&#34;Image1&#34; Width=&#34;200px&#34; Visible=&#34;false&#34; Height=&#34;100px&#34; ImageUrl=&#34;~/images/Desert.jpg&#34; runat=&#34;server&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;/table&gt; &lt;/FooterTemplate&gt; &lt;/asp:DataList&gt; &lt;/div&gt; &lt;/form&gt;</pre> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">protected void Submit_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(Constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT UserName, status FROM UserLogin WHERE UserName= &#39;&#34; + txtuserName.Text + &#34;&#39;&#34;, con)) { DataTable dt = new DataTable(); using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { sda.Fill(dt); dlStatus.DataSource = dt; dlStatus.DataBind(); } } } } protected void dlStatus_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { if ((e.Item.FindControl(&#34;lblStatus&#34;) as Label).Text.ToUpper() == &#34;TRUE&#34;) { (e.Item.FindControl(&#34;Image1&#34;) as Image).Visible = true; (e.Item.FindControl(&#34;lblStatus&#34;) as Label).Visible = true; (e.Item.FindControl(&#34;lblStatusName&#34;) as Label).Visible = true; } } }</pre> <p><span style="text-decoration: underline;">&nbsp;Screenshot</span></p> <p><span style="text-decoration: underline;"><img src="http://i988.photobucket.com/albums/af3/mudassarkhan/954159.gif" alt="" width="472" height="353" /></span></p> <p>&nbsp;</p>http://www.aspforums.net/Threads/954159/Show-hide-Label-based-on-user-status-using-C-in-ASPNet/http://www.aspforums.net/Threads/954159/Show-hide-Label-based-on-user-status-using-C-in-ASPNet/Thu, 03 Nov 2016 05:08:47 GMT