天天看点

如何用C#创建一个类并在其他Web页中调用该类的方法(2)

写好这个类后,如何调用呢,比如在CPKAnalysis.aspx页面调用 using System; using System.Collections;using System.ComponentModel; using System.Data;using System.Drawing; using System.Web;using System.Web.SessionState; using System.Web.UI;using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;   using System.IO;using System.Threading; using System.Globalization;using System.Reflection;using System.Resources; using System.Data.OracleClient;//oracle 数据库连接需要的命名空间 using System.Data.OleDb;using System.Configuration;//Access 数据库连接需要的命名空间   namespace SFCWEB {      ///<summary>      /// Summary description for CPKAnalysis.      ///</summary>      public class CPKAnalysis : System.Web.UI.Page      {          SFCWEB.bin.Stone StoneFunction=new SFCWEB.bin.Stone(); // 为了调用类中的方法需要在此声明,StoneFunction相当于这个类的实例          static string[,] storedata2=new string[100,8]; // 静态数组,一旦赋值,则不会变更,直到程序结束 private void Page_Load(object sender, System.EventArgs e)          {               if(!Page.IsPostBack)               {                                                                                       }          }          private void ModelSelected(object sender, System.EventArgs e)          {                      GC.Collect ();     string model=DropDownListModel.SelectedItem.Value; string model1=DropDownListModel.SelectedItem.Text;               if(model==" 请选择项目名")               {    msg_label.Visible=true; msg_label.Text=" 项目名不能为空";          }               else               {                  // 将工站显示到下拉框方法3,利用Access数据库                    ArrayList itestitemList= new ArrayList ();     int icount=0;                    string project=model1.ToString();                    OleDbConnection myconn1= new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Request.PhysicalApplicationPath+(ConfigurationSettings.AppSettings["AccessParth"]));      StoneFunction.GetStationFromAccess(itestitemList,ref icount,project,myconn1);      // 调用实例StoneFunction的GetStationFromAccess()方法                    DropDownListStation.Items.Clear();// 将下拉框的内容清空                    DropDownListStation.Items.Add("All");                    for (int i=0;i<icount;i++)// 将工站的内容添加到下拉框控件中                    {    DropDownListStation.Items.Add(itestitemList[i].ToString()); }               } } } }   

继续阅读