Dynamic dropdownlist in repeater, ASP.NET

匆匆过客 提交于 2019-12-05 21:48:46

The problem is you need to fill the DropDownList possible options before you set the selected value which you are trying to do inline with the Eval. I would switch it to use the OnDataBinding of the DropDownList and do what you need there.

Example:

<asp:DropDownList ID="ddlName" runat="server" OnDataBinding="ddlName_DataBinding" />

protected void ddlName_DataBinding(object sender, System.EventArgs e)
{
    DropDownList ddl = (DropDownList)(sender);

    // Fill your ddl here (eg. ddl.Items.Add("abc", xyz");
    // Make sure the value you are going to set the selected item to has been added

    // Now set the selected value since it will now exist.
    ddl.SelectedValue = Eval("ddl").ToString(); 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!