string strConn;
string strSQL;
SqlConnection sqlConn;
int ID = 0;
protected void Page_Load(object sender, EventArgs e)
{
strConn = System.Configuration.ConfigurationManager.AppSettings["ConnectString"];
sqlConn = new SqlConnection(strConn);
if (!IsPostBack)
{
this.BigClass();
this.SmallClass(ID);
}
}
protected void BigClass()
{
SqlCommand sqlComm = new SqlCommand();
sqlComm.Connection = sqlConn;
strSQL = "SELECT * FROM tBigClass";
sqlComm.CommandText = strSQL;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlComm;
DataSet ds = new DataSet();
sqlComm.Connection.Open();
sda.Fill(ds, "tBigClass");
ddlBigClass.DataSource = ds.Tables["tBigClass"];
ddlBigClass.DataTextField = "MBTitle";
ddlBigClass.DataValueField = "ID";
ddlBigClass.DataBind();
ddlBigClass.Items.Insert(0, new ListItem("请选择--", ""));
sqlComm.Connection.Close();
}
protected void SmallClass(int ID)
{
SqlCommand sqlComm = new SqlCommand();
sqlComm.Connection = sqlConn;
strSQL = "SELECT * FROM tSmallClass WHERE MSPid=@MSPid";
sqlComm.CommandText = strSQL;
sqlComm.Parameters.Add(new SqlParameter("@MSPid", SqlDbType.Int));
sqlComm.Parameters["@MSPid"].Value = ID;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlComm;
DataSet ds = new DataSet();
sqlComm.Connection.Open();
sda.Fill(ds, "tSmallClass");
ddlSmallClass.DataSource = ds.Tables["tSmallClass"];
ddlSmallClass.DataTextField = "MSTitle";
ddlSmallClass.DataValueField = "ID";
ddlSmallClass.DataBind();
ddlSmallClass.Items.Insert(0, new ListItem("请选择--", ""));
sqlComm.Connection.Close();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
protected void ddlBigClass_SelectedIndexChanged(object sender, EventArgs e)
{
ID = Convert.ToInt32(ddlBigClass.SelectedValue);
this.BigClass();
ddlBigClass.SelectedValue = ID.ToString() ;
this.SmallClass(ID);
}