如何在下拉列表中设置项目 [英] How to set items in dropdownlist

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

问题描述

我有一个下拉列表和内容..

I have a dropdownlist and contents..

DropDownList1.Items.Insert(0, new ListItem("Select user type", "Default value"));
             DropDownList1.Items.Insert(1, new ListItem("Administrator"));
             DropDownList1.Items.Insert(2, new ListItem("Operator"));
             DropDownList1.Items.Insert(3, new ListItem("Clerck"));


当我没有选择项目并单击按钮时,选择自动选择用户类型的项目的原因是什么?


When I do not select the item and click the button,select user type item selected automatically why?

推荐答案

当您按下按钮时,它会自动选择,导致按钮按下页面时出现再次加载并调用Page_load事件.
和DropDownList1再次填充.
!isPostBack 放在Page_load中,然后将代码粘贴到!isPostBack
when you press button it selects automatically cause on button press page get''s loaded again and Page_load event gets called.
and DropDownList1 filled again.
put !isPostBack in your Page_load, and paste your code under !isPostBack


if (!this.Page.IsPostBack) {
  //fill select box here
}



试试这个



try this


它应该添加
DropDownList1.Items.Insert(0, new ListItem("Select user type", "Default value"));


在databind()


after databind()


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

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