当按下按钮时,我调用了这段代码:
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.ToString() =="ER00 - File Header")
{
using (SqlConnection con =
new SqlConnection(ConfigurationSettings.AppSettings["DBcon"]))
{
if (String.IsNullOrEmpty(TextBox_ID.Text.ToString()))
{
lbl_NoBatchID.Text = "Please enter BatchID!";
}
else
{
try
{
SqlCommand sqlCommand = new SqlCommand(
"Select * from tbl_WinApps_FileHeader Where BatchID =" +
TextBox_ID.Text.ToString());
sqlCommand.Connection = con;
con.Open();
SqlDataReader read = sqlCommand.ExecuteReader();
GridView1.DataSource = read;
GridView1.DataBind();
}
catch (Exception)
{
}
}
}
}
}
它是这样工作的:用户输入一个ID,然后当按下按钮时,它将在SQL中显示表格。
如果用户没有在文本框中输入任何内容,则会提示“请输入 BatchID!” 但在那之后,它就留在那儿,即使我已经输入了有效的身份证,它也不会清除。知道为什么吗?