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.Bind (Populate) Label using SqlDataSource from Code Behind in ASP.Net<p>Hi <a class="username" rel="nid@patel">nid@patel</a>,</p> <p>Refer below code.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:Label ID=&#34;lblName&#34; runat=&#34;server&#34; /&gt; &lt;asp:SqlDataSource ID=&#34;SqlDataSource1&#34; runat=&#34;server&#34; ConnectionString=&#34;&lt;%$ ConnectionStrings:ConnectionString %&gt;&#34; ProviderName=&#34;&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;&#34; DataSourceMode=&#34;DataSet&#34; SelectCommand=&#34;SELECT [Name] FROM [Customers] WHERE ([Id] = ?)&#34; OnSelecting=&#34;SqlDataSource1_Selecting&#34;&gt; &lt;SelectParameters&gt; &lt;asp:Parameter Name=&#34;Id&#34; Type=&#34;Int32&#34; /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&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;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); foreach (DataRowView row in dv) { lblName.Text = row[&#34;Name&#34;].ToString(); } } } protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { e.Command.Parameters[&#34;Id&#34;].Value = 1; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)Handele Me.Load If Not Me.IsPostBack Then Dim dv As DataView = CType(SqlDataSource1.[Select](DataSourceSelectArguments.Empty), DataView) For Each row As DataRowView In dv lblName.Text = row(&#34;Name&#34;).ToString() Next End If End Sub Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs) e.Command.Parameters(&#34;Id&#34;).Value = 1 End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/176424/Bind-Populate-Label-using-SqlDataSource-from-Code-Behind-in-ASPNet/https://www.aspforums.net:443/Threads/176424/Bind-Populate-Label-using-SqlDataSource-from-Code-Behind-in-ASPNet/Thu, 22 Aug 2019 06:19:08 GMT