问题是我从下拉列表中获取名称,然后从表中获取该名称的学生 ID。
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
stud_name1 = ddl.SelectedValue;// sends the value
// Label1.Text = ddl.SelectedValue;
string getquery = "select studnt_id from Student where name='"+stud_name1+"'";
getidcon.Open();
SqlCommand getid = new SqlCommand(getquery, getidcon);
stdid1 = ((int)getid.ExecuteScalar());// gives the id in return to selection
// Session [stdid1]
// Label1.Text = stdid1.ToString();// testing value
// get the roll number
}
获得 id 后,我将其存储在 stdid1 全局变量中,但我没有获得存储在按钮代码中 stdid1 变量中的值。
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = stdid1.ToString();
}