dropdownlist 在后台绑定数据后, 怎么再读数据库内容赋给它的第一项

beg200710 2010-09-30 05:55:10
dropdownlist 在后台绑定数据后, 怎么再读数据库内容赋给它的第一项

if (!IsPostBack)
{
DataTable dt2 = SqlHelper.Query("select * from YProduct where YP_ID="+Request["YP_ID"]).Tables[0];
if (dt2.Rows.Count > 0)
{
dropdownlist.DataSource = dt2;
dropdownlist.DataBind();
}
DataTable dt = SqlHelper.Query("select * from YProduct where YP_ID=" + Request.QueryString["YP_ID"]).Tables[0];
if (dt.Rows.Count > 0)
{
dropdownlist.selectItem= dt.Rows[0][6].ToString();//这个怎么写才能把读的数据赋给dropdownlist的第一项显示啊(即dropdownlist框中显示)
}

...全文
132 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hejiasoft 2010-10-03
  • 打赏
  • 举报
回复
先绑定,绑定完了,再加
listitem li = new listitem();
li.text = "新加的项";
li.value = "0";
droupdownlist.items.insertof(li,0);
这样就可以了。


低价源码出售了,全是自己开发的代码,希望和大家一起交流,集百家之所长,希望能对大家有所帮助。
网店地址:http://shop36675020.taobao.com
beg200710 2010-10-01
  • 打赏
  • 举报
回复
上述方法试了不行,怎么办啊
wuyq11 2010-09-30
  • 打赏
  • 举报
回复
dropdownlist.DataSource=ds;
dropdownlist.DataValueField="id";
dropdownlist.DataTextField="name";
dropdownlist.DataBind();
dropdownlist.SelectedValue= dt.Rows[0][6].ToString()
PandaIT 2010-09-30
  • 打赏
  • 举报
回复
dropdownlist.Items.add(new listItem(dt.Rows[0][6].ToString()))

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧