日期:2014-05-19  浏览次数:21137 次

如何给DropDownList动态赋值?
按照搜索出来的结果

<%
string[]   achDrives=Directory.GetLogicalDrives();

int   nNumOfDrives=achDrives.Length;

for   (int   i=0;i <nNumOfDrives;i++)
        DropDownList1.SelectedValue   =   achDrives[i];        
%>

生成的页面中DropDownList没有数据,这里应该怎么改?

------解决方案--------------------
没有数据就不用赋值了呗
------解决方案--------------------
应该是 DropDownList1.Items.Add吧
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDicFrameCode();
}
}

/// <summary>
/// 绑定页面结构组成字典
/// </summary>
private void LoadDicFrameCode()
{
DicPagePartCodeBLL dicPagePartCodeBLL = new DicPagePartCodeBLL();
ddl_DicPagePartCode.DataSource = dicPagePartCodeBLL.GetAllDicPagePartCodes();
ddl_DicPagePartCode.DataValueField = "Id ";
ddl_DicPagePartCode.DataTextField = "FPagePartName ";
ddl_DicPagePartCode.DataBind();
}