我们在“编辑资料”这个功能中经常会用到这一点。比如我们添加某条新闻时设定类别为“国内新闻”,那么在编辑该新闻时,页面刚加载时,怎么让dropdownlist中“国内新闻”这一项被默认选中呢。
...读取数据库(略)
DropDownList1.DataSource = dt1;
DropDownList1.DataTextField = "category";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
DropDownList1.SelectedValue = dt1.Rows[0][0].ToString();                 这一句是重点
其中dt1.Rows[0][0].ToString()就是类别那一列。