01.
using
System;
02.
using
System.Collections;
03.
using
System.Configuration;
04.
using
System.Data;
05.
using
System.Linq;
06.
using
System.Web;
07.
using
System.Web.Security;
08.
using
System.Web.UI;
09.
using
System.Web.UI.HtmlControls;
10.
using
System.Web.UI.WebControls;
11.
using
System.Web.UI.WebControls.WebParts;
12.
using
System.Xml.Linq;
13.
using
System.Data.SqlClient;
14.
using
System.Drawing;
15.
using
System.Collections.Generic;
16.
17.
namespace
Project1
18.
{
19.
public
partial
class
ViewCourse : System.Web.UI.Page
20.
{
21.
22.
protected
void
Page_Load(
object
sender, EventArgs e)
23.
{
24.
if
(Session[
"Staff_User"
] ==
null
)
25.
{
26.
Page.Response.Redirect(
"../Login.aspx"
);
27.
}
28.
else
29.
{
30.
if
(!Page.IsPostBack)
31.
{
32.
if
(Request.QueryString[
"ViewCourseID"
] ==
null
)
33.
{
34.
bindData();
35.
}
36.
}
37.
}
38.
39.
}
40.
public
void
bindData()
41.
{
42.
string
_cons = ConfigurationManager.AppSettings[
"ConnectDB"
].ToString();
43.
44.
SqlConnection _con =
new
SqlConnection(_cons);
45.
46.
string
_strSelect =
"SELECT course_id, course_name_thai FROM course"
;
47.
48.
SqlCommand _selectCmd =
new
SqlCommand(_strSelect, _con);
49.
50.
SqlDataReader _dr;
51.
52.
try
53.
{
54.
_con.Open();
55.
_dr = _selectCmd.ExecuteReader();
56.
57.
if
(_dr.HasRows)
58.
{
59.
ddl_course.DataSource = _dr;
60.
ddl_course.DataTextField =
"course_name_thai"
;
61.
ddl_course.DataValueField =
"course_id"
;
62.
ddl_course.DataBind();
63.
}
64.
else
65.
{
66.
67.
}
68.
}
69.
finally
70.
{
71.
_con.Close();
72.
}
73.
}
74.
75.
76.
protected
void
btn_ok_Click(
object
sender, EventArgs e)
77.
{
78.
string
viewCourseID = ddl_course.SelectedValue.ToString();
79.
Page.Response.Redirect(
"ViewCourse.aspx?ViewCourseID="
+ viewCourseID);
80.
}
81.
82.
}
83.
}