protected void Page_Load(object sender, EventArgs e)
{
string[] stringArray = new string[6];
stringArray[0] = "a";
stringArray[1] = "b";
stringArray[2] = "c";
stringArray[3] = "d";
stringArray[4] = "e";
stringArray[5] = "f";
for (int i = 0; i < stringArray.Length; i++) {
this.DropDownList1.Items.Add(new ListItem(stringArray[i]));
} }这样DropDownList1.SelectedItem.ToString()也是a,b,c,d,e,f了也就是说如果让value为0,1,2,3,4,5
解决方案 »
- 怎么做一个全局的错误信息
- asp.net实例下载地址
- ASP.NET Mvc 连打
- 不行了不行了,查询老是调不出来,总是500服务器错误,急死了,我真的很不懂,求助!
- bin目录下有dll,xml等等文件,其中xml文件什么用啊?
- web.config文件的<forms>标签中,path="/"是什么意思?
- WebService部署的后连接数据库出错
- 如何让div层居在最顶端,主要是居在<select></select>标签的上面?
- 赶紧救命,一台widows2003的机子无法执行asp.net的程序
- 帮我一个忙 急 如何在模板中对字符串格式化?请你们吃饭....
- C#连接oracle带ip地址的字符串是什么呢,怎么搜到的全是连接本地的oracle呢
- 系统分析报告怎么写 (顶贴有分)
正解
{
List<controlData> cd = new List<controlData>();
cd.Add(new controlData("one", "0.1"));
cd.Add(new controlData("two", "0.2"));
cd.Add(new controlData("three", "0.3"));
cd.Add(new controlData("four", "0.4"));
cd.Add(new controlData("five", "0.5"));
cd.Add(new controlData("six", "0.6"));
cd.Add(new controlData("seven", "0.7"));
cd.Add(new controlData("eight", "0.8"));
cd.Add(new controlData("nine", "0.9"));
cd.Add(new controlData("ten", "1.0")); tools.controlData.BindList(cd, "strid", "strname", ListBox1);
tools.controlData.BindList(cd, "strid", "strname", ListBox2);
tools.controlData.BindList(cd, "strid", "strname", ListBox3);
tools.controlData.BindList(cd, "strid", "strname", ListBox4);
tools.controlData.BindList(cd, "strid", "strname", ListBox5);
tools.controlData.BindList(cd, "strid", "strname", ListBox6);
tools.controlData.BindList(cd, "strid", "strname", ListBox7);
tools.controlData.BindList(cd, "strid", "strname", ListBox8);
tools.controlData.BindList(cd, "strid", "strname", ListBox9);
}
楼主改一下
为什么每选一次就都会增加列表的项目.
比如初使是6项选择一次就大于6项了
/// 继承基类ListControl的数据控件,如:DropDownList,ListBox,CheckBoxList,RadioButtonList,BulletedList.
/// 参数 string text 可以为空.
/// </summary>
public static void BindList(object dataSource, string text, string value, ListControl lst)
{
lst.DataSource = dataSource;
lst.DataTextField = text;
lst.DataValueField = value;
lst.DataBind();
}
正解
this.DropDownList1.Items.Add(new ListItem(stringArray[i], i));
dropdownlist.dataVAluefield="编号";