0
在我的(網頁形式)應用程序,我已經定義定義我的名單如何通過點擊每個按鈕來循環顯示列表對象中的項目?
public class DepartmentList
{
public int DeptID { get; set; }
public string DepartmentName { get; set; }
}
然後我填滿它與SQL數據。注意:此代碼是一個按鈕(submitdata)內點擊:
using (SqlConnection conn2 = newSqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString))
{
SqlCommand cmd1 = new SqlCommand("Select [id], [Department] from Departments Where " + UserDefined + conn2);
conn2.Open();
using (SqlDataReader reader2 = cmd1.ExecuteReader())
{
while (reader2.Read())
{
DepartmentList dl = new DepartmentList();
dl.DeptID = reader2.GetInt32(0);
dl.DepartmentName = reader2.GetString(1);
DepartmentList.Add(dl);
}
}
我看見了,在這裏嘗試了example from this post,這是非常相似,我想除了在這個示例中使用的陣列和陣列做內容和索引是預定義的。我該如何做同樣的事情,而是使用一個List對象並用每個按鈕(rotateData)單擊打印每個項目?
+1,因爲我一直在試圖找出同樣的東西。我也一直在關注你以前的帖子。偉大的問題! – 2014-09-03 01:57:40
什麼按鈕點擊?它是ASP.Net webforms,MVC或WinForms?請更具描述性。 – Mrchief 2014-09-03 01:58:17
其asp.net webforms我爲歧義道歉。 – Skullomania 2014-09-03 02:05:52