Asp.net - 在DropDownList的顶部添加空白项 [英] Asp.net - Add blank item at top of dropdownlist

查看:531
本文介绍了Asp.net - 在DropDownList的顶部添加空白项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下拉没有显示我的空白项第一?以下是我有

Why is the dropdown not showing my blank item first? Here is what I have

drpList.Items.Add(New ListItem("", ""))

With drpList
    .DataSource = myController.GetList(userid)
    .DataTextField = "Name"
    .DataValueField = "ID"
    .DataBind()
End With

编辑〜我绑定到一个Generig列表,可这是罪魁祸首?

Edit ~ I am binding to a Generig List, could this be the culprit?

推荐答案

您的数据绑定后:

drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty));
drpList.SelectedIndex = 0;

这篇关于Asp.net - 在DropDownList的顶部添加空白项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆