【发布时间】:2014-03-27 11:54:40
【问题描述】:
我正在尝试在 asp.net 的列表框中显示日期。我有以下网络方法及其在输入学生 ID 时的工作。然后我如何在我的页面中调用此 Web 方法以在列表框中仅显示日期。
[WebMethod]
public List<Attendance> StudentAttendance(int SID)
{
List<Attendance> listofAttendance = new List<Attendance>();
cn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM tblAttendance WHERE StudentID = " + SID +"", cn);
SqlDataReader sr = com.ExecuteReader();
while (sr.Read())
{
Attendance getdattendance = new Attendance();
getdattendance.ID = sr.GetInt32(0);
getdattendance.StudentID = sr.GetInt32(1);
getdattendance.RegistrationDate = sr.GetDateTime(2);
listofAttendance.Add(getdattendance);
}
sr.Close();
cn.Close();
return listofAttendance;
}
在列表框中显示日期
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserAuthentication"] != null)
{
Student s = (Student)Session["UserAuthentication"];
Attendance[] a = attend.StudentAttendance(s.StudentID);
ListBox1.Text = display list of dates with the following format ("dd MMM yyyy"
// lbAttendance.Text = a.RegistrationDate.Date.ToString("dd MMM yyyy", System.Globalization.CultureInfo.InstalledUICulture);
}
else
{
Response.Redirect("Index.aspx");
}
}
【问题讨论】:
标签: c# asp.net sql web-services webmethod