按数据集填充下拉列表时,在下拉列表中添加项目 [英] Adding Item in dropdown when filling dropdown by dataset

查看:64
本文介绍了按数据集填充下拉列表时,在下拉列表中添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在按数据集填充下拉列表.现在,我正在尝试在dropdowm中添加一项,但最后要添加项.

我正在按照以下方式工作

Hello,

I am filling drop down by dataset. Now I am trying to add one item in the dropdowm,but item is getting added in the end.

I am working in following way

dropdown1.DataSource = dataset;
dropdown1.DataTextField = "name";
dropdown1.DataValueField = "pk";
dropdown1.DataBind();
dropdown1.Items.Add(new ListItem(All, "-1"));



所有单词都将添加到列表的末尾.

请告诉我这样,以便所有单词都将作为第一项而不是最后一项添加.

谢谢.



All word is getting added in the end of the list.

Please tell me the way, so that All word will add as first item not the last.

Thanks.

推荐答案

尝试一下,
Try this,
dropdown1.Items.Insert(0, "All");


int x=0;
for(int i=0;i<=ds.Tables[0].Rows.count-1;i++)
{
DropDownList1.Items.Add(ds.Tables[0].rows[i].itemArray[0].ToSrting());
x++;
}



欢呼!!!!!!!!!



cheers!!!!!!!!!


这篇关于按数据集填充下拉列表时,在下拉列表中添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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