问一个简单的dropdownlist的问题! 如果直接绑定数据库的话,那么显示的全是数据。我想在第一项中加个“全部”的字段项,有没有个简单的方法? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 绑定后再Page_Load中写if(!IsPostBack){ DropDownList1.Items.Add("全部",0);}然后再DropDownList的SelectedIndexChanged事件中为此“全部”做处理(value 0); dropdownlist.Items.Insert(0,new ListItem( "全部", "-1 ")); if (!Page.IsPostBack) { //数据绑定 this.控件ID.Items.Insert(0, new ListItem("全部", "-1")); } DropDownList1.DataSource=datatable;DropDownList1.value="id";DropDownList1.Text="name";DropDownList1.DataBind();DropDownList1.Items.Insert(0, "全部"); //........DropDownList1.DataBind();//以上是DropDownList1直接绑定数据库代码//以下就是你需要的效果 DropDownList1.SelectedIndex = -1; ListItem list1 = new ListItem(); list1.Text = "全部"; list1.Value = "-1"; list1.Selected = true; DropDownList1.Items.Insert(0,list1); this.DropDownList1.Items.Insert(0, new ListItem("全部", "0")); 动态绑定,开始插入this.DropDownList1.Items.Insert(0, new ListItem("全部", "0"));后面的你自己插入,注意后面的值域要不一样 aspx问题。。。帮个忙啊 C#开发苹果移动设备程序掉线后怎么自动重试,求高手解答 Session丢失问题 怎样在UpdatePanel 内实现 msgbox? 分层的意义 asp.net如何实现程序与美工分离 关于访问ASPX页面时图片出不来的问题? 请问httpResponse与Response有什么区别啊? 如何指定excel中的sheet名啊? 马上要过年了,求助一点资源。。。 DataList嵌套gridview并对gridview分页 曲线图问题~~~~~~~~~~~~急~~~~~!!!!!!!!
if(!IsPostBack)
{
DropDownList1.Items.Add("全部",0);
}然后再DropDownList的SelectedIndexChanged事件中为此“全部”做处理(value 0);
if (!Page.IsPostBack)
{
//数据绑定
this.控件ID.Items.Insert(0, new ListItem("全部", "-1"));
}
DropDownList1.value="id";
DropDownList1.Text="name";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "全部");
//........
DropDownList1.DataBind();
//以上是DropDownList1直接绑定数据库代码
//以下就是你需要的效果
DropDownList1.SelectedIndex = -1;
ListItem list1 = new ListItem();
list1.Text = "全部";
list1.Value = "-1";
list1.Selected = true;
DropDownList1.Items.Insert(0,list1);
后面的你自己插入,注意后面的值域要不一样