0% found this document useful (0 votes)
9 views5 pages

Practical No. 8

The document outlines a practical assignment for Advanced Web Programming, focusing on creating a web application that demonstrates data binding using DetailsView, FormView, and GridView controls. It includes code snippets for each control, detailing how to connect to a SQL database, retrieve employee data, and bind it to the respective controls. The assignment is intended for students in the TY-BSCIT program, specifically for semester V.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Practical No. 8

The document outlines a practical assignment for Advanced Web Programming, focusing on creating a web application that demonstrates data binding using DetailsView, FormView, and GridView controls. It includes code snippets for each control, detailing how to connect to a SQL database, retrieve employee data, and bind it to the respective controls. The assignment is intended for students in the TY-BSCIT program, specifically for semester V.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

TY-BSCIT SUBJECT: Advanced Web Programming

Practical No. 8

AIM: Create a web application to demonstrate data binding


using DetailsView and FormView Control.
A. DetailsView Control
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace p8a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindFormView();
}
}
private void BindFormView()
{
var conn = new SqlConnection("Data Source=JCC-
GIGABYTE;Initial Catalog = tyit; Integrated Security = True");
var cmd = new SqlCommand("SELECT * FROM Employee",
conn);
var adapter = new SqlDataAdapter(cmd);
var ds = new DataSet();
adapter.Fill(ds, "Employee");
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
}
protected void DetailsView1_PageIndexChanging1(object
sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
BindFormView();
}
SEM-V Roll no.: 711
TY-BSCIT SUBJECT: Advanced Web Programming
}
}

Output:

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming
B. FormView Control.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace p8b
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindFormView();
}
}
private void BindFormView()
{
var conn = new SqlConnection("Data Source=JCC-GIGABYTE;Initial Catalog = tyit;
Integrated Security = True");
var cmd = new SqlCommand("SELECT * FROM Employee", conn);
var adapter = new SqlDataAdapter(cmd);
var ds = new DataSet();
adapter.Fill(ds, "Employee");
FormView1.DataSource = ds;
FormView1.DataBind();
}
protected void FormView1_PageIndexChanging1(object sender,
FormViewPageEventArgs e)
{
FormView1.PageIndex = e.NewPageIndex;
this.BindFormView();
}
}
}

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming
Output:

C. GridView Control

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace p8c
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=JCC-
GIGABYTE;Initial Catalog=tyit;Integrated Security = True";
String selectSQL = "SELECT * FROM Employee";
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);

con.Open();
DataSet ds = new DataSet();
adapter.Fill(ds, "Employee");
GridView1.DataSource = ds.Tables["Employee"];
GridView1.DataBind();
con.Close(); ;
}
}
}

OUTPUT:

SEM-V Roll no.: 711

You might also like