我正在尝试将搜索文本框(使用存储过程)与网格视图绑定,但是当我运行它们并键入搜索条件时,不会显示任何结果并且 GridView 会自动显示。我尝试了很多方法,包括使用 DataAdapter 和 DataSet 来填充搜索文本框的结果,然后将 DataSet 绑定到 GridView。但它也不起作用这里是代码:
protected void SearchButton_Click(object sender, EventArgs e)
try
{
string con_str = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(con_str);
SqlCommand com = new SqlCommand("dbo.SearchRecords", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter pDocumentTitle = new SqlParameter("@Doc_Title", SearchTextBox.Text);
SqlParameter pUserID = new SqlParameter("@User_ID", SearchTextBox.Text);
SqlParameter pDocumentType = new SqlParameter("@Doc_Type", SearchTextBox.Text);
SqlParameter pDocumentDescription = new SqlParameter("@Doc_Description",SearchTextBox.Text);
com.Parameters.Add(pDocumentTitle);
com.Parameters.Add(pUserID);
com.Parameters.Add(pDocumentType);
com.Parameters.Add(pDocumentDescription);
con.Open();
SqlDataAdapter DA = new SqlDataAdapter(com);
com.ExecuteNonQuery();
DataSet t = new DataSet();
DA.Fill(t);
GridView1.DataBind();
GridView1.DataSource = t;
}
catch (Exception ex)
{
Label2.Text = ex.Message;
//throw;
}
}