using System; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Collections.Generic; namespace ReportViewerLib { public class Customer { public string strCustomerID; public string strCompanyName; public string strContactName; public string strCountry; public string CustomerID { get { return strCustomerID; } set { strCustomerID = value; } } public string CompanyName { get { return strCompanyName; } set { strCompanyName= value; } } public string ContactName { get { return strContactName; } set { strContactName= value; } } public string Country { get { return strCountry; } set { strCountry= value; } } public static List { SqlConnection cnn=new SqlConnection( ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); SqlCommand cmd=new SqlCommand(); cmd.Connection=cnn; cmd.CommandText="select CustomerID,CompanyName,ContactName,Country from customers where country=@country"; SqlParameter p=new SqlParameter ("@country",country); cmd.Parameters.Add(p); cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); List while (reader.Read()) { Customer c = new Customer(); c.CustomerID = reader.GetString(0); c.CompanyName = reader.GetString(1); c.ContactName = reader.GetString(2); c.Country = reader.GetString(3); list.Add(c); } cnn.Close(); return list; } public static List { SqlConnection cnn = new SqlConnection( ConfigurationManager.ConnectionStrings ["NorthwindConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = "select CustomerID,CompanyName,ContactName,Country from customers"; cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); List while (reader.Read()) { Customer c = new Customer(); c.CustomerID = reader.GetString(0); c.CompanyName = reader.GetString(1); c.ContactName = reader.GetString(2); c.Country = reader.GetString(3); list.Add(c); } cnn.Close(); return list; } } } |
protected void DropDownList1_SelectedIndexChanged (object sender, EventArgs e) { if (DropDownList1.SelectedValue == "All") { ObjectDataSource1.SelectMethod = "GetAllCustomers"; ObjectDataSource1.SelectParameters.Clear(); ReportParameter param = new ReportParameter ("SubTitle", "List of all the customers"); ReportParameter[] p ={ param }; ReportViewer1.LocalReport.SetParameters(p); } else { ObjectDataSource1.SelectMethod = "GetCustomersForCountry"; ObjectDataSource1.SelectParameters[0].DefaultValue = DropDownList1.SelectedValue; ReportParameter param = new ReportParameter ("SubTitle", "List of customers for a country"); ReportParameter[] p ={ param }; ReportViewer1.LocalReport.SetParameters(p); } } |