c# - DropDownList 获得空白选择

标签 c# asp.net gridview

我有一个由代码直接从数据库填充的下拉列表。但是在底部有一个没有值(value)的可选项目。我怎样才能纯粹/完全地绑定(bind)数据库中的数据,以避免将来出现这种空白选择?

   protected void DropDownList_OnDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList ddlName = (DropDownList)e.Row.FindControl("ddlName");

            ddlName.DataSource = MyClass.NameList();
            ddlName.DataTextField = "Name";
            ddlName.DataValueField = "id";
            ddlName.DataBind();

        }
    }

最佳答案

尝试删除您的代码声明“”并重新键入。这将从头开始刷新您的下拉列表,并在删除时清除其所有引用。您当前的下拉列表可能会引用您项目开发过程中的某个地方。

关于c# - DropDownList 获得空白选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22625069/

相关文章:

c# - 如何将 XElement 转换为 XDocument

javascript - 如何在 ASP.NET 中从 Facebook 登录检索访问 token ?

javascript - 如果 DropDownList 选定索引已更改,则隐藏 gridview 行

asp.net - 在 ASP.net 中模拟 HttpSessionState 以进行 nunit 测试

php - Yii2:如何根据前几页的总和在页脚中添加总和?

asp.net - Gridview 编辑时自动完成文本框

c# - EF orderby/thenby 组合扩展方法

c# - 在 C# 中管理线程关系

c# - 如何使用 DataContractJsonSerializer 将类类型而不是命名空间序列化为 Json 字符串

c# - EPPlus 无法访问已关闭的流