0
在我的網頁中,我能夠成功檢索所有記錄。我正在使用下拉列表根據不同的「狀態」過濾記錄。但是,它只顯示第一個檢索到的記錄。沒有任何例外或錯誤。當我在我的數據庫中運行查詢(以測試我的sql語句)時,有3個檢索到的記錄。我仍然無法確定我的代碼中出了什麼問題。Gridview只顯示第一條記錄
我正在研究一個三層web應用程序。
這裏是我的表示層代碼,
protected void ddl_status_SelectedIndexChanged(object sender, EventArgs e)
{
string status = ddl_status.SelectedItem.ToString();
//Default
if (status == "Show All Submissions")
{
gv_combinedEntries.Visible = true;
SubmissionBLL sBLL = new SubmissionBLL();
//Call getAllStudent() method in StudentBLL
List<Submission> subAll = new List<Submission>();
subAll = sBLL.getAllSub();
gv_combinedEntries.DataSource = subAll;
gv_combinedEntries.DataBind();
}
else
{
SubmissionBLL subStatus = new SubmissionBLL();
List<Submission> subList = new List<Submission>();
subList = subStatus.getStatusList(status);
gv_combinedEntries.DataSource = subList;
gv_combinedEntries.DataBind();
}
}
業務邏輯層:
public List<Submission> getStatusList(string statusPick)
{
List<Submission> specificStatus = new List<Submission>();
Submission sub2 = new Submission();
specificStatus = sub2.getStatusNewList(statusPick);
return specificStatus;
}
數據訪問層:
public List<Submission> getStatusNewList(string statusSelected)
{
List<Submission> subStatus = new List<Submission>();
string Id, School, TeamName, submissionDate, status;
string queryStr = "SELECT s.Id,c.School,c.TeamName,s.submissionDate,
c.submissionStatus FROM TeamSubmission s INNER JOIN Competition c
ON c.teamUsername = s.username WHERE submissionStatus = @enterStatus";
SqlConnection conn = new SqlConnection(_connStr);
SqlCommand cmd = new SqlCommand(queryStr, conn);
cmd.Parameters.AddWithValue("@enterStatus", statusSelected);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Id = dr["Id"].ToString();
School = dr["School"].ToString();
TeamName = dr["TeamName"].ToString();
submissionDate = dr["submissionDate"].ToString();
status = dr["submissionStatus"].ToString();
subStatus.Add(new Submission(Id, School, TeamName, submissionDate, status));
}
conn.Close();
dr.Close();
dr.Dispose();
return subStatus;
}
你有沒有通過您的代碼加強,並證實「子列表」或「subAll」有一個以上的價值? – 2015-02-05 20:35:49