list 集合,把数据绑定到dropdownlist
ArrayListarr=newArrayList();Class1c1=newClass1();c1.a=11;c1.b=12;arr.Add(c1);Class1c2...
ArrayList arr = new ArrayList();
Class1 c1 = new Class1();
c1.a = 11;
c1.b = 12;
arr.Add(c1);
Class1 c2 = new Class1();
c2.a = 21;
c2.b = 22;
arr.Add(c2);
this.DropDownList2.DataSource = arr;
this.DropDownList2.DataBind();
这样做不行啊,哎 展开
Class1 c1 = new Class1();
c1.a = 11;
c1.b = 12;
arr.Add(c1);
Class1 c2 = new Class1();
c2.a = 21;
c2.b = 22;
arr.Add(c2);
this.DropDownList2.DataSource = arr;
this.DropDownList2.DataBind();
这样做不行啊,哎 展开
展开全部
DropDownList2必须设置DataValueField和DataTextField属性,来指明DropDownList要显示的Value和Text,这要看你的Class1怎么定义的了
假设
public class Class1
{
public int Id { get; set; }
public string Text { get; set; }
}
那么可以
this.DropDownList2.DataSource = arr;
this.DropDownList2.DataTextField = "Text";
this.DropDownList2.DataValueField = "Id";
this.DropDownList2.DataBind();
假设
public class Class1
{
public int Id { get; set; }
public string Text { get; set; }
}
那么可以
this.DropDownList2.DataSource = arr;
this.DropDownList2.DataTextField = "Text";
this.DropDownList2.DataValueField = "Id";
this.DropDownList2.DataBind();
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
当绑定的是个对象集合的时候,会把对象集合当初数据表处理 就要赋值DataTextField 和DataValueField 确定绑定的前后台值
DropDownList2.DataSource = arr;
DropDownList2.DataTextField = "a";
DropDownList2.DataValueField = "b";
DropDownList2.DataBind();
DropDownList2.DataSource = arr;
DropDownList2.DataTextField = "a";
DropDownList2.DataValueField = "b";
DropDownList2.DataBind();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.DropDownList2.DataSource = arr;
this.DropDownList2.DisplayMember = "a";
this.DropDownList2.ValueMember= "b";
this.DropDownList2.DisplayMember = "a";
this.DropDownList2.ValueMember= "b";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询