我想重载DropDownList1.Item.Add()方法。让它可以加入一个对象。
因为它默认加入的对象item只有Text,Value两具属性。我希望在Add()中能加入一个结构体就好了。象这种效果:
struct student
{
int Age;
bool Sex;
string Name;
}
DropDownList.Items.Add(student stu, string Text); //后面的参数是用来显示的。
因为它默认加入的对象item只有Text,Value两具属性。我希望在Add()中能加入一个结构体就好了。象这种效果:
struct student
{
int Age;
bool Sex;
string Name;
}
DropDownList.Items.Add(student stu, string Text); //后面的参数是用来显示的。
下拉框只有text和value
你加入这个对象到底哪几个属性作为text哪几个作为value呢?
不明白你的意思啊
DropDownList1.Item.Add(new ListItem("text","value"))一般都是这样的
放个id吧
提交之后根据id遍历
------------------------------------------
这样的话覆盖默认的ToString()方法就可以了
class stu
{
public string name;
public string password;
public override string ToString()
{
return this.name+":"+this.password;
}
}
stu stu1=new stu();
stu1.name="aa";
stu1.password="bb";
DropDownList1.Items.Add(new ListItem(stu1.name,stu1.ToString()));
DropDownList1.DataBind();
不过VC里有种作法:
用STL map,一个字符串对应一个结构体。在本地存储数据。象后台的一个表由多个记录组成一样。map <String, CStudent> mapStudent;
mapStudent["Joe Lennon"] = CStudent(103547, 22);
我暂时不知道放到C#里怎么用。
public class myDropDownList:DropDownList
{
struct student
{
int Age;
bool Sex;
string Name;
}public void Addstruct(struct student,string Text)
{
//从struct中取出 student的信息,依次添加
this.Item.Add(new ListItem("text","value"));
}}