2013-07-16 5 views
0

VB.NET에서 코드 뒤에 DataTable을 만들었습니다. 내 .ASPX 페이지에서 호출해야하며이를 ListView로 표시해야합니다.데이터를 목록보기로 가져 오기

내 코드 뒤에 다음과 같습니다

Dim table As New DataTable 

' columns in the DataTable. 
table.Columns.Add("Monday", System.Type.GetType("System.Int32")) 
table.Columns.Add("Tuesday", System.Type.GetType("System.Int32")) 
table.Columns.Add("Wednesday", System.Type.GetType("System.Int32")) 
table.Columns.Add("Thursday", System.Type.GetType("System.Int32")) 
table.Columns.Add("Friday", System.Type.GetType("System.Int32")) 
' rows with those columns filled in the DataTable. 
table.Rows.Add(1, 2005, 2000, 4000, 34) 
table.Rows.Add(2, 3024, 2343, 2342, 12) 
table.Rows.Add(3, 2320, 9890, 1278, 2) 
table.Rows.Add(4, 3420, 1234, 4321, 89) 
table.Rows.Add(5, 3240, 6600, 1100, 56) 
table.Rows.Add(6, 4320, 1100, 3243, 23) 
table.Rows.Add(7, 4540, 7645, 4324, 56) 

내가 .aspx 페이지에 만 보여 월요일과 화요일 싶습니다. 내가 어떻게 할까? 그 순간 나는 이것을 가지고있다 :

이것은 뒤에 aspx 코드에서? 당신의 ASPX에서

Property readonly Data() As DataTable 



End Property 

답변

1

다음

<asp:ListView ID="table" runat="server" ItemPlaceholderID="itemPlaceholder"> 
     <LayoutTemplate> 
      <table> 
       <tr> 
        <th> 
        </th> 
        <th> 
         monday 
        </th> 
        <th> 
         tuesday 
        </th> 
       </tr> 
       <tr runat="server" id="itemPlaceholder" /> 
      </table> 
     </LayoutTemplate> 
     <ItemTemplate> 
      <tr id="Tr1" runat="server"> 
       <td> 
        <asp:Label ID="lblmon" runat="Server" Text='<%#Eval("monday") %>' /> 
       </td> 
       <td> 
        <asp:Label ID="lbltues" runat="Server" Text='<%#Eval("tuesday") %>' /> 
       </td> 
      </tr> 
     </ItemTemplate> 
    </asp:ListView> 

와의

당신 vb.net 다음

ASCX에서
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load 
    Dim table As New DataTable 

    ' columns in the DataTable. 
    table.Columns.Add("Monday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Tuesday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Wednesday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Thursday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Friday", System.Type.GetType("System.Int32")) 
    ' rows with those columns filled in the DataTable. 
    table.Rows.Add(1, 2005, 2000, 4000, 34) 
    table.Rows.Add(2, 3024, 2343, 2342, 12) 
    table.Rows.Add(3, 2320, 9890, 1278, 2) 
    table.Rows.Add(4, 3420, 1234, 4321, 89) 
    table.Rows.Add(5, 3240, 6600, 1100, 56) 
    table.Rows.Add(6, 4320, 1100, 3243, 23) 
    table.Rows.Add(7, 4540, 7645, 4324, 56) 

    Me.table.DataSource = table 
    Me.table.DataBind() 
End Sub 

는 방법이 코드를 넣어 호출 Page_Load에

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

Private Sub BindData() 
    Dim table As New DataTable 

    ' columns in the DataTable. 
    table.Columns.Add("Monday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Tuesday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Wednesday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Thursday", System.Type.GetType("System.Int32")) 
    table.Columns.Add("Friday", System.Type.GetType("System.Int32")) 
    ' rows with those columns filled in the DataTable. 
    table.Rows.Add(1, 2005, 2000, 4000, 34) 
    table.Rows.Add(2, 3024, 2343, 2342, 12) 
    table.Rows.Add(3, 2320, 9890, 1278, 2) 
    table.Rows.Add(4, 3420, 1234, 4321, 89) 
    table.Rows.Add(5, 3240, 6600, 1100, 56) 
    table.Rows.Add(6, 4320, 1100, 3243, 23) 
    table.Rows.Add(7, 4540, 7645, 4324, 56) 

    Me.table.DataSource = table 
    Me.table.DataBind() 
End Sub 
+1

내 코드를 페이지에 배치하십시오. ID를 변경하고 테스트 웹 사이트에서 코드를 테스트 한 결과 작동합니다. – Mez

+1

@ mali 당신이 관리 했습니까? – Mez

+1

새 웹 사이트를 만들고 새 기본 페이지를 추가하고 내 .ASPX 및 .ASPX.VB를 각각 붙여 넣으십시오. 당신은 그것의 걸림 새를 아주 쉽게 잡아야한다. – Mez

관련 문제