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); } } |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |