添加“无"到数据绑定下拉列表 [英] add "None " to databound dropdown list
本文介绍了添加“无"到数据绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表,绑定到后面代码中的数据.
我希望默认值是-无-在列表的顶部.
如果用户选择列表的顶部,即无",则应提示,如pl z从列表中选择,
如果用户选择-无"以外的其他选项,则应继续执行该过程
我已将顶部列表添加为
Hi,
I have a dropdownlist that is bound to data in the code behind.
i want the default to be -- None -- at the top of the list.
if the user select the top of list i.e --None-- it should prompt as pl z select from the list ,
if user select the other than --None-- then it should continue the process
i have added the top list as
drop down.Items.Insert(0, new ListItem("-- None--", ""))
如何验证
在此先感谢
how to validate
thanks in advance
推荐答案
使用此功能.
use this one.
drop down.Items.Insert(0, new ListItem("-- None--", "-- None--"));
dropdownlist1.Items.Insert(0, new ListItem("None", "0"));
用于验证,您可以使用javascript例如
for validating you can use javascript for example
try
{
if(dropdownlist1.SelectedValue == "0")
{
throw new Exception("<script language="javascript">" + "alert('Please select something');" + "");
}
}
catch (Exception ex)
{
label1.Text = ex.Message;
}</script>
function validateDropDown(){
if(document.getElementById(<%=ddl.ClientID%>).value=='0')
{
alert('please select valid item.');
return false;
}
}
这篇关于添加“无"到数据绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文