public void dr_Bind(string strCmd, DropDownList dr)
{
SqlDataAdapter adp = new SqlDataAdapter(strCmd, myConnection);
DataSet ds = new DataSet();
adp.Fill(ds);
dr.DataSource = ds;
return;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string str_dept = "select * from lab_dept";
string str_major = "select * from lab_major";
string str_grade = "select * from lab_grade";
co_class_add.dr_Bind(str_dept, drp_dept);
drp_dept.DataBind();
co_class_add.dr_Bind(str_major, drp_major);
drp_major.DataBind();
co_class_add.dr_Bind(str_grade, drp_grade);
drp_grade.DataBind();
if (Request["Action"] == "edit")
{
string num = Request["Class_num"];
string sqlstr = "select * from lab_class where class_num like " + num + "";
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["labConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlconn);
DataSet ds = new DataSet();
da.Fill(ds);
txt_class.Text = ds.Tables[0].Rows[0]["class_ID"].ToString();
txt_num.Text = ds.Tables[0].Rows[0]["class_stunum"].ToString();
txt_bizhu.Text = ds.Tables[0].Rows[0]["class_bizhu"].ToString();
drp_dept.SelectedValue = ds.Tables[0].Rows[0]["dept_ID"].ToString();
drp_major.SelectedValue = ds.Tables[0].Rows[0]["major_ID"].ToString();
drp_grade.SelectedValue = ds.Tables[0].Rows[0]["class_grade"].ToString();
}
}
}