protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[,] booklist ={
{"001","C# 3.0"},
{"002","ASP.NET3.5"},
{"003","三國演義"},
{"004","水浒"},
{"005","西游記"}
};
for (int i = 0; i < booklist.GetLength(0); i++)
{
// DrowdownList只能顯示二維數組中的一個維度,這裡顯示的是書名
ddlBooks.Items.Add(new ListItem(booklist[i, 1], booklist[i, 0]));
}
}
}
protected void ddlBooks_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlBooks.SelectedIndex != -1)
{
lblBooks.Text = string.Format
("書名:{0},號碼:{1}", this.ddlBooks.SelectedItem.Text,
this.ddlBooks.SelectedValue);
}
}