我在表格中遇到问题。有两个文本字段,然后有下拉菜单,链接到数据库。
当我点击下拉菜单时,我的两个文本字段变空了。
protected void OnChange_Acdemics(object Sender, EventArgs e)
{
DropDownList list = (DropDownList)Sender;
string value = (string)list.SelectedValue;
// degrees_dropdown.Visible = true;
try
{
// String query = "SELECT Degree_types.detail,Degree_Detail.GPA FROM Degree_Detail INNER JOIN Degree_types ON Degree_Detail.Degree_tilte = Degree_types.Degree_title where Degree_types.degree_type = '" + value + "';";
String query = "Select detail from Degree_Detail where id=" + int.Parse(value) + ";";
Dt = dbComm.GetDataTable(query);
Degree_Selection.DataTextField = "detail";
// Degree_Selection.DataValueField = "GPA";
Degree_Selection.DataSource = Dt;
Degree_Selection.DataBind();
}
catch (Exception ex)
{
}
}
答案 0 :(得分:2)
您需要使用Page.IsPostBack
:
if(!Page.IsPostBack)
{
// load page
}
else
{
// check input values and set it again
}