У меня есть WebForm before_adm.aspx.cs, который имеет следующий код:
.
.
.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDown abs =new DropDown();
abs.DropDown();
}
.....
Я хочу вызвать функцию DropDown (), которая находится в файле DropDown.cs. Код в DropDown.cs выглядит следующим образом:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
/// <summary>
/// Summary description for DropDown
/// </summary>
public class DropDown
{
public DropDown()
{
try
{
OdbcConnection myConn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=10.155.160.130;Database=testcase;User=root;Password=;Option=3;");
OdbcCommand myCmd = new OdbcCommand("select skey,casecode from casetype", myConn);
myConn.Open();
OdbcDataReader myReader = myCmd.ExecuteReader();
//Set up the data binding.
DropDownList3.DataSource = myReader;
DropDownList3.DataTextField = "skey";
DropDownList3.DataValueField = "casecode";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, "<-- Select -->");
}
catch (Exception ex)
{
Response.Write(ex.StackTrace);
}
if (DropDownList2.SelectedItem.Text == "Register")
{
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("STA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("STM"));
}
else if (DropDownList2.SelectedItem.Text == "Stamp")
{
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("WP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("FA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("LPA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CAPL"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("MCA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("XFER"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ARP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("TXA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRIR"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("WPCR"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AO"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CONP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ELEP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COAP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ARA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CREF"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ITA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AAR"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("XFA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("TACR"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("EXAP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUE"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUW"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRMA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CAREV"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CONF"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("PILWP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMWP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("XOB"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMCP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AELEP"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("RUIT"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CS"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("RUCA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRIA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CUSA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("EXA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMCRC"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("EA"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRMAB"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRMAM"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COAPM"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CPM"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("MCAM"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AS"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("PILSM"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRREF"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMCR"));
DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUSFC"));
}
else if (DropDownList2.SelectedItem.Text == "<-- Select -->")
{
DropDownList3.Items.Clear();
}
}
}
Что бы я ни делал до сих пор, это правильно? Теперь я получаю сообщение об ошибке:
The name 'DropDownList2' does not exist in the current context
The name 'DropDownList3' does not exist in the current context
The name 'Response' does not exist in the current context
Я хочу создать эту функцию, потому что я буду создавать много таких веб-форм, и я хочу вызвать ту же функцию для
DropDownList2_SelectedIndexChanged
Какие параметры мне нужно передать. Я хочу знать, как передать параметры. Пожалуйста, ведите меня. Я хочу создать много таких функций в файле .cs, который будет иметь много других пользовательских элементов управления.