我遇到了將方法綁定到gridview的麻煩,有人可以幫忙嗎? 基本上,我返回的數據集在getAllPatients method
,然後傳遞給asp.net頁面。當我去加載頁面沒有任何反應。將方法綁定到gridview
這裏是我的方法:
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();
}
}
一個空的「catch」不會「讓.NET處理它」。異常的傳播/冒泡停止在捕獲和w/out(重新)拋出,正常執行繼續。我認爲在這種情況下可能會發生異常並不知道它。 – radarbob
Wheres gridview? AutogeneratingColumns是否等於true? – Fals
是的AutogeneratingColumns現在設置爲true,但沒有區別 –