How to asp.net single value data binding in asp.net with c#


How to asp.net single value data binding in asp.net with c#

 In this article, I am going to explain with example how to create a single value data binding in asp.net in both the C#

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>asp.net single value data binding example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <h2 style="color:Teal">Example: Single Value Data Binding [Using Variable]</h2>
            <asp:Label ID="Label1" runat="server" Font-Size="Large">
                User ID: <%# UserID %><br />
                UserName: <%# UserName %><br />
                City: <%# City %>
            </asp:Label>
        </div>
        </form>
    </body>
    </html>




Source Code:-

  1. using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class DataBindingExample : System.Web.UI.Page
    {
        public int UserID;
        public string UserName;
        public string City;

        protected void Page_Load(object sender, EventArgs e)
        {
            UserID = 1;
            UserName = "srkcode";
            City = "Lucknow";

            this.DataBind();
        }
    }








Post a Comment

0 Comments