我想从数据库读去数据后在第一个位子显示数据库内容
例如
原来 北京
天津
上海
数据库这个字段是 天津
我要的效果是进入修改页面后
DROPdownlist控件的显示为
天津
北京
上海
就是在数据库中的文件显示在第一位
我不想要
天津
北京
天津
上海
这样的效果啊,大家把代码贴出来看看啊. 把绑定控件的代码也写出来啊,我看看有没有多加什么字段;
例如
原来 北京
天津
上海
数据库这个字段是 天津
我要的效果是进入修改页面后
DROPdownlist控件的显示为
天津
北京
上海
就是在数据库中的文件显示在第一位
我不想要
天津
北京
天津
上海
这样的效果啊,大家把代码贴出来看看啊. 把绑定控件的代码也写出来啊,我看看有没有多加什么字段;
this.DROPdownlist.DataSource = aaa;
this.DROPdownlist.DataBind();
this.DROPdownlist.Items.Remove("天津");
this.DROPdownlist.Items.Insert(0, "天津");
数据分两个库了 第一个库内容为
北京
天津
上海
在添加时选择
在修改页面通过ID 我想读取上传的内容
数据内容为
姓名 所在城市
小二 天津
小三 北京
如果是小二让DROPdownlist控件把小二的所在城市显示在DROPdownlist的最前面
例如
天津
北京
上海
如果是小三
就显示 北京
天津
上海
这次能不能明白???
string id=this.dropdownlist1.selectitem.value.tostring();
然后根据条件查询咯
select ct_name from city where name='"+id+"' order by ct_name;
然后把数据绑定到你想要的dropdownlist2控件上
this.dropdownlist2.datasource=sda;
this.dropdownlist2.datatextfield="ct_name";
this.dropdownlist2.databind();ps;如果你是在一个控件上面实现 把它置顶就OK拉
int i_ToDelete = -1;
for (int i = 0; i < this.DropDownList1.Items.Count; i++)
{
if (this.DropDownList1.Items[i].Value == "2")
{
i_ToDelete = i;
liTemp.Text = this.DropDownList1.Items[i].Text;
liTemp.Value = this.DropDownList1.Items[i].Value;
}
}
if (i_ToDelete > -1)
{
this.DropDownList1.Items.RemoveAt(i_ToDelete);
this.DropDownList1.Items.Insert(0, liTemp);
}
自动读去该人 所对应的城市 将他绑定为dropdownlist的默认值 是不是?
如果这样的话
你就需要去
dp1.Items.FindByValue(Convert.ToString(DataBinder.Eval(e.Item.DataItem,"字段值"))).Selected = true;
13楼正解。dp1.Items.FindByValue(‘数据库读出的值’).Selected = true;