我想重载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); //后面的参数是用来显示的。
解决方案 »
- delphi编写的dll在C#中如何调用?
- 程序自动重启
- 在winform中如何将动态数据填充到有一定格式的Excel模板中
- 类的继承问题?????
- 在TreeView中如何做到类似QQ的添加组的功能?
- Listbox内的item怎么读入数据库啊 ?
- datagrid的初级问题~
- C# ListView....怎么让某一列出现一个下拉框??
- c#调试问题!!!!!! 在线等待
- 短信猫开发中碰到的超时和状态报告错误的问题
- 救命,用ASP。NET和C#做的一个网站,进入首页时速度奇慢,真是要短命几年,有解决办法吗?请进谢谢!!!
- c#中如何才能使用coolbar控件或者如何使用其他方法实现coolbar控件的类似功能呢???????????送分!
下拉框只有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"));
}}