绑定DropDownList方法

aspx上的代码(id类别id,name为类别名称,均和数据库字段相同):
<asp:DropDownList ID="ddlCateID" runat="server" DataTextField="name" DataValueField="id" ></asp:DropDownList>

aspx.cs中的绑定:
Code

在编辑类别的aspx页面中的反绑:
ddlCateID.SelectedValue = news.CaId.ToString();
这样,当你点点击编辑新闻时,页面中的类别列表,也会根据数据库中当前的类别id,自动selected到对应的类别名上。
posted @ 2009-09-10 17:17  王翔(kingfly)  阅读(213)  评论(0编辑  收藏  举报