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.
14.
public
partial
class
_Default : System.Web.UI.Page
15.
{
16.
protected
void
Page_Load(
object
sender, EventArgs e)
17.
{
18.
19.
string
SqlConnectionString =
"Your connection string."
;
20.
string
SqlCommandString =
"Select [ClassID], [ClassName] From [Global_UserClass]"
;
21.
SqlDataSource DataSource =
new
SqlDataSource(SqlConnectionString, SqlCommandString);
22.
23.
24.
DropDownList1.DataSource = DataSource;
25.
DropDownList1.DataTextField =
"ClassName"
;
26.
DropDownList1.DataValueField =
"ClassID"
;
27.
DropDownList1.DataBind();
28.
29.
30.
foreach
(ListItem item
in
DropDownList1.Items)
31.
{
32.
if
(item.Value ==
"5"
)
33.
item.Selected =
true
;
34.
}
35.
}
36.
}