DropDownList控件绑定数据库
来源:互联网 发布:网络刺客ii使用教程 编辑:程序博客网 时间:2024/04/30 05:52
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState.ToString().Contains("Edit")) //如果控件在模板列的编辑状态下就加这个条件
{
DropDownList dd = e.Row.FindControl("DropDownList1") as DropDownList;
DataClassesDataContext lqDB = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["qiyezhanConnectionString"].ConnectionString.ToString());
var result = from r in lqDB.Table1
where r.id > 0
select r;
dd.DataSource = result;
dd.DataValueField = "FieldValue"; //绑定的字段名
dd.DataTextField = "FieldValue";
dd.DataBind();
dd.Items.Insert(0, new ListItem("—请选择—", "0")); //另外添加列表项
dd.SelectedValue = ((Label)(e.Row.Cells[9].Controls[1])).Text.ToString(); //指定默认列表项,或者直接赋值为"0"表示"请选择"项
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState.ToString().Contains("Edit")) //如果控件在模板列的编辑状态下就加这个条件
{
DropDownList dd = e.Row.FindControl("DropDownList1") as DropDownList;
DataClassesDataContext lqDB = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["qiyezhanConnectionString"].ConnectionString.ToString());
var result = from r in lqDB.Table1
where r.id > 0
select r;
dd.DataSource = result;
dd.DataValueField = "FieldValue"; //绑定的字段名
dd.DataTextField = "FieldValue";
dd.DataBind();
dd.Items.Insert(0, new ListItem("—请选择—", "0")); //另外添加列表项
dd.SelectedValue = ((Label)(e.Row.Cells[9].Controls[1])).Text.ToString(); //指定默认列表项,或者直接赋值为"0"表示"请选择"项
}
}
}
- DropDownList控件绑定数据库
- 数据库信息绑定DropDownList控件的Item
- DropDownList控件绑定
- 绑定DropDownList控件
- DropDownList 绑定数据库
- DropDownList绑定数据库
- DropDownList 控件如何绑定数据
- DropDownList控件的数据绑定
- DropDownList控件的数据绑定
- DropDownList和数据库绑定实例
- CascadingDropDown从数据库中读取数据绑定到DropDownList控件上
- asp.net ajaxtoolkit CascadingDropDown从数据库中读取数据绑定到DropDownList控件上
- CascadingDropDown从数据库中读取数据绑定到DropDownList控件上
- 绑定Enum到DropDownList控件的方法
- 绑定Enum到DropDownList控件的方法
- 绑定控件数据源对于DropDownList类型的
- 泛型list<T>绑定dropdownlist控件
- DataSet绑定ListBox、DropDownList、RadioButtonList、CheckBoxList控件
- 开启 java 征途
- Java程序程序程序程序员应该掌握的 项技能
- LINQ查询条件为字段值在数组中
- Java 转型 super的用法回顾
- 配置CentOS 6.2 第三方yum源(CentOS默认的标准源里没有nginx软件包)
- DropDownList控件绑定数据库
- GridView中的控件属性的引用
- 第05章 数组 14 练习 12
- 变量未赋到值时不可使用
- tomcat启动startup.bat一闪而过
- LINQ to SQL数据集是IQueryable类型
- GlusterFS之文件系统扩展属性
- 对QT namespace UI的理解
- LINQ查询数据集第一条数据