2014-04-07 2 views
0

나는 보통 컨트롤 이러한 유형의 작동하지 않는, 그래서 나는 완전히 여기에 잘못된 궤도에 수 ... 최종 목표는 ProductTitle와 기록의 데이터 집합을 가지고있다및 디스플레이

, ProductURL 및 ProductDescription. 그런 다음 필요한 경우 추가 행이있는 레코드를 3 열 형식으로 표시하십시오. 예를 들어 :

기록 1, 2, 3, 4, 5, 6, 7은 내가지고있어 오류가

System.Web가

1 - 2 - 3 

4 - 5 - 6 

7 

입니다 표시되어야합니다. HttpException : DataBinding : 'System.Web.UI.WebControls.ListItem'에 'ProductTitle'이라는 이름의 속성이 없습니다.

프런트 엔드 측면 :

<div> 
    <asp:ListView ID="ListView1" runat="server" GroupItemCount="3" OnLoad="ListView1_Load"> 

     <LayoutTemplate> 
      <table> 
       <tr> 
        <td> 
         <table border="0" cellpadding="5"> 
          <asp:PlaceHolder runat="server" ID="groupPlaceHolder"></asp:PlaceHolder> 
         </table> 
        </td> 
       </tr> 
      </table> 
     </LayoutTemplate> 

     <GroupTemplate> 
      <tr> 
       <asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder> 
      </tr> 
     </GroupTemplate> 

     <ItemTemplate> 
      <td> 
       <div> 
        <div><%#Eval("ProductTitle")%></div> 
        <img alt="Test Image" src="<%#Eval("ProductURL")%>" /> 
        <div><%# Eval("ProductDescription")%></div> 
       </div> 
      </td> 
     </ItemTemplate> 

    </asp:ListView> 
</div> 

내 코드 숨김있어 :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

End Sub 


Protected Sub ListView1_Load(sender As Object, e As EventArgs) 
    Dim myPaaams As ArrayList = New ArrayList 

    myPaaams.Add(New ListItem("ProductTitle", "Adams Test")) 
    myPaaams.Add(New ListItem("ProductURL", "Adams Test")) 
    myPaaams.Add(New ListItem("ProductDescription", "Adams Test")) 

    ListView1.DataSource = myPaaams 
    ListView1.DataBind() 
End Sub 

이 나는 ​​또한에 대한 다음 코드를 시도했습니다 내 ListView 이벤트를로드하지만 동일한 오류로 실패합니다.

Protected Sub ListView1_Load(sender As Object, e As EventArgs) 
    Dim myParams As ArrayList = New ArrayList 

    Dim variable As New Dictionary(Of String, String) From {{"ProductTitle", "Adams Test"}, _ 
                  {"ProductURL", "value2"}, _ 
                  {"ProductDescription", "value2"}} 

    myParams.Add(variable) 

    ListView1.DataSource = myParams 
    ListView1.DataBind() 
End Sub 

답변

1

당신은

Public Class Products 
    Public Property ProductTitle As String 
    Public Property ProductURL as String 
    Public Property ProductDescription as String 
End Class 


Protected Sub ListView1_Load(sender As Object, e As EventArgs) 
    Dim myParams As BindingList(of Products)= New BindingList(of Products) 

    Dim p as Products = New Products With {.ProductTitle = "Title", 
             .ProductURL = "URL", 
             .ProductDescription="Description"} 

    myParams.Add(p) 
    ListView1.DataSource = myParams 
    ListView1.DataBind() 
End Sub 

같은

다음은 수동으로 새 목록 항목을 만들려고하고 있기 때문에 당신이 작동하지 않는하려고하는 것은 왜 이유, 다음, 클래스를 사용할 필요가 그것에 대해 바인딩 - 그 목록 항목은 올바른 속성을 가지고 있지 않기 때문에, 작동하지 않습니다.

+0

그냥 시도했지만 여전히 동일한 오류 메시지가 나타납니다. ListView1.DataBind()에서 오류가 발생했습니다 – adam

+0

내 코드에서 오타가 수정되어 aspx 코드가 새 프로젝트 (img를 div로 변경)로 복사되고 codebehind에 내 코드가 붙여 넣어졌습니다 - 작동 (bindinglist 가져 오기 추가 후). – jmoreno

+0

이것이 ASCX가 아니라 ASPX가 아니라는 점이 차이점이 있습니까? 우리는 DNN에서 일하며 모든 코드는 전체 페이지가 아닌 별도의 모듈/컨트롤에서 수행됩니다. – adam