問題は、ドロップダウンリストから名前を取得し、テーブルからその名前の学生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();
}