Performing ADO.NET data access in ASP.NET for

 a. Simple Data Binding

 b. Repeated Value Data Binding.

a. Simple Data Binding:

Aspx:

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="PR6A.aspx.cs"Inherits="WebApplication1.PR6A"%>

 

<!DOCTYPEhtml>

 

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title></title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:LabelID="Label1"runat="server">

EMPID:<%#empid%><br/>

Empname:<%#empname%><br/>

City:<%#city%>

 

</asp:Label>

</div>

</form>

</body>

</html>

Aspx.cs:

using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

 

namespace WebApplication1

{

publicpartialclassPR6A : System.Web.UI.Page

    {

publicintempid;

publicstringempname;

publicstring city;

protectedvoidPage_Load(object sender, EventArgs e)

        {

empid = 1;

empname = "kunal";

city = "mulund";

 

this.DataBind();

        }

    }

}

OUTPUT:

Simple Data Binding

b. Repeated Value Data Binding

Aspx:

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="PR6B.aspx.cs"Inherits="WebApplication1.PR6B"%>

 

<!DOCTYPEhtml>

<scriptrunat="server">

protectedvoidpage_load(object sender, System.EventArgs e)

        {

List<string>DataToolBoxControls = newList<string>();

DataToolBoxControls.Add("GridView");

DataToolBoxControls.Add("DetailsView");

DataToolBoxControls.Add("FormView");

            ListBox1.DataSource = DataToolBoxControls;

            DropDownList1.DataSource = DataToolBoxControls; ;

            RadioButtonList1.DataSource = DataToolBoxControls; ;

            CheckBoxList1.DataSource = DataToolBoxControls;

 

this.DataBind();

 

        }

</script>

 

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title></title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ListBoxID="ListBox1"runat="server"></asp:ListBox>

<br/><br/>

<asp:DropDownListID="DropDownList1"runat="server"></asp:DropDownList>

<br/><br/>

<asp:RadioButtonListID="RadioButtonList1"runat="server"></asp:RadioButtonList>

<br/><br/>

<asp:CheckBoxListID="CheckBoxList1"runat="server"></asp:CheckBoxList>

 

</div>

</form>

</body>

</html>

 

 

Aspx.cs:

using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

 

namespace WebApplication1

{

publicpartialclassPR6B : System.Web.UI.Page

    {

protectedvoidPage_Load(object sender, EventArgs e)

        {

 

        }

    }

}

output:

Repeated Value Data Binding

Post a Comment

0 Comments