제네릭 목록을 리피터에 바인딩하는 데 문제가 있습니다. generic 목록에 사용 된 유형은 실제로 struct입니다.구조체 유형 일반 목록을 반복기에 바인딩
나는 기본적인 예를 아래에 내장했습니다
struct Fruit
{
public string FruitName;
public string Price; // string for simplicity.
}
protected void Page_Load(object sender, EventArgs e)
{
List<Fruit> FruitList = new List<Fruit>();
// create an apple and orange Fruit struct and add to List<Fruit>.
Fruit apple = new Fruit();
apple.FruitName = "Apple";
apple.Price = "3.99";
FruitList.Add(apple);
Fruit orange = new Fruit();
orange.FruitName = "Orange";
orange.Price = "5.99";
FruitList.Add(orange);
// now bind the List to the repeater:
repFruit.DataSource = FruitList;
repFruit.DataBind();
}
나는 과일을 모델링하는 간단한 구조체를 가지고, 우리는 FruitName과 가격 두 가지 속성이 있습니다. 먼저 'FruitList'유형의 빈 제네릭 목록을 작성합니다.
그런 다음 struct (apple and orange)를 사용하여 두 개의 과일을 만듭니다. 이 과일은 목록에 추가됩니다.
마지막으로, 리피터의 데이터 소스 속성에 일반 목록 ...
마크 업이 다음과 같습니다 바인딩 :
<asp:repeater ID="repFruit" runat="server">
<ItemTemplate>
Name: <%# Eval("FruitName") %><br />
Price: <%# Eval("Price") %><br />
<hr />
</ItemTemplate>
나는 과일 이름을 볼 것으로 예상을하고 가격은 화면에 인쇄되고 수평선으로 구분됩니다. 내가 바인딩 실제에 관한 오류를 얻고 순간
...**Exception Details: System.Web.HttpException: DataBinding: '_Default+Fruit' does not contain a property with the name 'FruitName'.**
나는이 일을 할 수 있는지 모르겠어요? 어떤 아이디어?
감사합니다.
랜덤 노트,리스트 뷰 클래스는 대규모 기능의 측면에서 중계기를 대체한다. –
@Chris Marisic 팁을 주셔서 감사합니다. 지금 ListView에 대해 읽고 있습니다. 정말 좋아 보입니다. http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control- part-1-building-a-product-listing-page-with-clean-css-ui.aspx – Dal