从下拉列表填充项目 [英] populating items from dropdownlist

查看:113
本文介绍了从下拉列表填充项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从服务器端填充它们时,我想在下拉列表中显示请选择....."作为第一项.

我后面有这个代码

I want to display "Please select....." as the first item in the dropdownlist while populating them from server side.

I have this code behind

ddldept.DataSource = emp.GetDepartments();
               ddldept.DataTextField = "deptid";
               ddldept.DataValueField = "deptname";
               ddldept.DataBind();



我有点困惑,请帮助

问候
sreekanth



i am getting bit confusion please help

regards
sreekanth

推荐答案

绑定下拉菜单后,添加以下代码:

Add below code after you bind your dropdown:

ddldept.DataSource = emp.GetDepartments();
               ddldept.DataTextField = "deptid";
               ddldept.DataValueField = "deptname";
               ddldept.DataBind();
ddldept.Items.Insert(0, new ListItem("--Please Select--", "0"));


这是代码

here is the code

ddldept.DataSource = emp.GetDepartments();
ddldept.DataTextField = "deptid";
ddldept.DataValueField = "deptname";
ddldept.DataBind();
ddldept.Items.Insert(0, new ListItem("Please select.....", "0"));



P.S.只需确保在验证时处理此请选择....."即可



P.S. just make sure you handle this "Please select....." while validations


尝试此
DropDownList1.Items.Insert(0,new ListItem("Please select"));


这篇关于从下拉列表填充项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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