DropDownList显示默认数据库值
问题如标题
T_DegreelevelControl.ascx里的代码如下
protected void Page_Load(object sender, EventArgs e)
{
}
override protected void OnInit(EventArgs e)
{
Bind();
}
protected void Bind()
{
TeacherBLL DlevelA = new TeacherBLL();
DropDownList1.DataSource =DlevelA.SelectAllDlevel();
DropDownList1.DataValueField = "Dl_DlevelID";
DropDownList1.DataTextField = "Dl_DlevelName";
DropDownList1.DataBind();
}
public String Text
{
get
{
this.EnsureChildControls();
return (DropDownList1.SelectedItem.Text);
}
set
{
this.EnsureChildControls();
DropDownList1.SelectedItem.Text = value;
}
}
}
在前台写了
<%@ Register src="Control/T_DegreelevelControl.ascx" tagname="T_DegreelevelControl" tagprefix="uc5" %>
<td class="tableleft2">学历层次:</td>
<td class="tableleft2"><uc5:T_DegreelevelControl ID="T_DegreelevelControl2" runat="server" /></td>
后台代码
this.T_DegreelevelControl2.Text = Convert.ToString(ds.Tables[0].Rows[0]["T_Edegreelevel"]);
但这样显示出来的是DropDownList的第一项
请问该怎么修改才能显示默认数据库的值
------解决方案--------------------DropDownList1.SelectedIndex = "默认值Dl_DlevelID的值"
------解决方案--------------------修改selectindext值
------解决方案--------------------
什么算是默认数据库的值啊?
------解决方案--------------------this.T_DegreelevelControl2.Items.FindByText(Convert.ToString(ds.Tables[0].Rows[0]["T_Edegreelevel"])).Selected = true;