ASP:RadioButtonList Databind自定义对象

时间:2009-08-05 18:14:29

标签: asp.net data-binding radiobuttonlist

嘿伙计们,我的ASP有点麻烦:RadioButtonList,谷歌和SO搜索,没有运气,你能帮助我吗?

我遇到数据绑定问题。我有一个看起来像这样的自定义类:

public class myClass{
  public myInnerClass{
    public int myID;
    public String myTextField;
    /* other fields*/
  }
  public List<myInnerClass> myList;
}

我正在尝试将其内部类的通用列表绑定到radiolist:

protected void Page_Load(object sender, EventArgs e){
  myClass data = anotherClass.getData();
  uxRadioList1.DataSource = data.myList;
  uxRadioList1.DataTextField = "myTextField";
  uxRadioList1.DataValueField = "myID";
  uxRadioList1.DataBind();
}

但它不会去。当我没有指定它绑定的DataTextField和DataValueField字段时,它会显示'myClass + myInnerClass'。我该怎么做呢?

1 个答案:

答案 0 :(得分:4)

我认为你只能绑定到公共属性,而不能绑定到字段。尝试将myInnerClass的字段更改为属性:

public class myClass{
  public myInnerClass{
    public int myID { get; set; }
    public String myTextField { get; set; }
    /* other fields*/
  }
  public List<myInnerClass> myList;
}