c#二維數組聲明簡單例子
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);
}
}
最後更新:2017-04-02 22:15:58