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);
            }
        }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydgzj.html