01.
void
Namelist()
02.
{
03.
if
(con.State == ConnectionState.Closed)
04.
con.Open();
05.
06.
cmd.CommandText =
"select * from [EmployeeData] where Section='GA&HR'"
;
07.
cmd.Connection = con;
08.
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
09.
da.Fill(ds,
"EmployeeData"
);
10.
con.Close();
11.
DropDownList6.DataSource = ds.Tables[
"EmployeeData"
];
12.
DropDownList6.DataTextField =
"Name"
;
13.
DropDownList6.DataValueField =
"EmployeeID"
;
14.
DropDownList6.DataBind();
15.
DropDownList6.Items.Insert(0,
"เลือกชื่อพนักงาน"
);
16.
}
17.
protected
void
DropDownList6_SelectedIndexChanged(
object
sender, EventArgs e)
18.
{
19.
if
(!Page.IsPostBack)
20.
{
21.
if
(con.State == ConnectionState.Closed)
22.
con.Open();
23.
cmd.CommandText =
"select * from [EmployeeData] where Name=@pName"
;
24.
cmd.Parameters.AddWithValue(
"@pName"
,DropDownList6.SelectedValue);
25.
cmd.Connection = con;
26.
SqlDataReader rd = cmd.ExecuteReader();
27.
while
(rd.Read())
28.
{
29.
TextBox15.Text = rd[0].ToString();
30.
TextBox19.Text = rd[2].ToString();
31.
TextBox21.Text = rd[3].ToString();
32.
}
33.
rd.Close();
34.
con.Close();
35.
}
36.
}