The EnhancedSpreadSheetControl Code-Behind Class File
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Configuration;
namespace ControlsBook2Web.Ch07
{
public partial class EnhancedSpreadSheetControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
EnhancedSpreadsheetControl1.DataBind();
344 CHAPTER 7 ?– SE RVER CONTROL DATA B INDING
SqlDataReader dr = GetCustomerDataReader();
EnhancedSpreadsheetControl2.DataSource = dr;
EnhancedSpreadsheetControl2.DataBind();
dr.Close();
}
private SqlDataReader GetCustomerDataReader()
{
SqlConnection conn =
new SqlConnection(WebConfigurationManager.
ConnectionStrings["NorthWindDB"].ConnectionString);
conn.Open();
SqlCommand cmd =
new SqlCommand("SELECT CustomerID, ContactName, ContactTitle,
CompanyName FROM Customers WHERE CustomerID LIKE '[AB]%'",
conn);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}
private void FillEmployeesDataSet(DataSet ds)
{
SqlConnection conn =
new SqlConnection(WebConfigurationManager.
ConnectionStrings["NorthWindDB"].ConnectionString);
conn.Open();
SqlDataAdapter da =
new SqlDataAdapter("SELECT EmployeeID, FirstName, LastName, Title
FROM Employees WHERE EmployeeID < 5",
conn);
da.
Pages:
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456