给DropDownList 控件加上"==请选择=="选项
来源:互联网 发布:linux nat 端口转发 编辑:程序博客网 时间:2024/05/16 11:03
1.给VS2003下的DropDownList添加"==请选择=="选项的方法
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
String sql="select * from ClassInfo";
SqlConnection con=new SqlConnection("server=.;uid=sa;pwd=sa;database=ManualAssign");
SqlDataAdapter sda = new SqlDataAdapter(sql,con);
DataSet ds =new DataSet();
sda.Fill(ds, "ClassInfo");
this.DropDownList1.DataSource = ds.Tables["ClassInfo"].DefaultView;
this.DropDownList1.DataTextField = "ClassName";
this.DropDownList1.DataValueField = "ClassId";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Insert(0,new ListItem("==请选择==","-1"));//在Item中添加在第0项,该Item的text值为==请选择==,实际的value是-1,注意这句一定要写在this.DropDownList1.DataBind();绑定语句后,写在前面无效
this.DropDownList1.Items.FindByValue("-1").Selected=true;
this.DataGrid1.Visible=false;
}
}
不加上If条件的话,无法选择下拉列表框的值,即使选中了也无法执行,因为当点击按钮时页面重新加载Load方法,默认还是选中“==请选择==”这个选项!
1.给VS2005下的DropDownList添加"==请选择=="选项的方法
请添加一个DropDownList 控件,后台写绑定语句,然后在其Items 中添加一个“==请选择==”项目。
最后一个关键点在于AppendDataBoundItems 属性,请将该属性设置为true,这样便能轻松完成功能的构建。
- 给DropDownList 控件加上"==请选择=="选项
- DropDownList 加上请选择
- dropdownlist添加请选择
- 给dropdownlist加默认选项
- DropDownList中的选项是从数据库中绑定的,但是如何在前面添加“请选择”?
- dropdownlist 默认填充 --请选择---
- DropDownList中“请选择”变色
- DropdownList添加下拉"请选择"
- 给DROPDOWNLIST加上TOOLTIP的效果
- dropdownlist控件 “选项”添加示例
- dropdownlist控件 添加“选项”
- 在DropDownList 中添加"请选择"
- 关于dropdownlist的请选择的问题
- 为DropDownList添加默认值“请选择”
- Dropdownlist添加一项——"请选择"
- 给自定义控件加上图标
- 给控件加上滚动条
- combox绑定table后,加上‘请选择’。
- 111
- 行为型之状态模式
- mingw-w64 系统更新,支持native Win x64下使用wxWidgets的GUI程序开发
- flash做一个时钟程序
- rman 命令
- 给DropDownList 控件加上"==请选择=="选项
- 截取一定长度的文章标题,超过指定长度,就加“...”
- abstract和interface的区别
- 无需明证
- java细节
- 手中无剑,心中有剑--程序员的最高境界
- 查询加密的数据对象
- httpClient应用
- 用JAVA做一个时钟程序