我在ASP.NET中有一个按钮控件,与Button_Click
函数对应
我有一个方法bindEmployeeDetailsToRepeater
从SQL表中检索数据。
bindEmployeeDetailsToRepeater
代码位于Button_Click
时,它会在我的转发器中显示信息,但bindEmployeeDetailsToRepeater
致电Button_Click
时,转发器没有显示任何内容。 有人可以解释为什么从Button_Click调用函数(如下面的代码示例中所示)不起作用吗?
void bindEmployeeDetailsToRepeater()
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["EConnectionString"].ConnectionString);
string cmdText = "SELECT * FROM employees where id='testo'";
SqlCommand cmd = new SqlCommand(cmdText, con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
Repeater1.DataSource = cmd.ExecuteReader();
Repeater1.DataBind();
con.Close();
}
protected void Button_Click(object sender, EventArgs e)
{
bindEmployeeDetailsToRepeater();
}