我无法将方法绑定到gridview,有人可以帮忙吗?基本上,我在中返回一个数据集,getAllPatients method
然后将其传递给 asp.net 页面。当我去加载页面时,什么也没有发生。
这是我的方法:
public DataSet GetAllPatients()
{
//create objects
SqlConnection conn = null;
SqlDataAdapter da = null;
DataSet ds = null;
string sql = string.Empty;
//create sql string
sql = "SELECT * FROM GP_Patient";
//create connection
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GPConn"].ConnectionString);
try
{
//create Data adapter
da = new SqlDataAdapter(sql, conn);
//fill dataset using data adapter
da.Fill(ds, "Patients");
}
catch
{
//don't do anything special, just let .Net handle it
}
finally
{
// close connection and release data adapter
if (conn != null)
{
conn.Close();
da.Dispose();
}
}
//output the dataset
return ds;
}
这是我的代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//create object
Patient ptn = new Patient();
//set datasource of control to objects method
gridview1.DataSource = ptn.GetAllPatients();
//bind
gridview1.DataBind();
}
}