2014-11-13 3 views
0

이 프로젝트를 실행하는 경우 데이터 페이지의 세 번째 페이지를 클릭 한 다음 새 목록을 목록보기에 바인딩하는 "개인"링크를 클릭하면 아무 것도 표시되지 않습니다. 디버거는 데이터 소스 개수 = 9가 정확한지 보여줍니다. Datasource 항목 수 또한 9이지만 0입니다.이 문제는 있지만 실제로 발생하는 이유를 파악할 수는 없습니다. 어떤 아이디어?asp listview 데이터 소스가 업데이트되지 않음

WebForm1.aspx.vb

Imports System.IO 

Public Class WebForm1 
Inherits System.Web.UI.Page 

Private publicPath As String = "~/public" 
Private privatePath As String = "~/private" 
Private physicalPath As String 

Private publicImage As New List(Of String) 
Private privateImage As New List(Of String) 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)) 
    Response.Cache.SetValidUntilExpires(False) 
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches) 
    Response.Cache.SetCacheability(HttpCacheability.NoCache) 
    Response.Cache.SetNoStore() 

    getObjects() 

    If Session("Mode") Is Nothing Then 
     Session("Mode") = "Public" 
    End If 
End Sub 


Private Sub Permissions_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender 
    'Binds the Data Before Rendering 
    BindData() 
End Sub 


Private Sub getObjects() 
    For x As Integer = 0 To 99 
     publicImage.Add(x.ToString + ".jpg") 
    Next 

    For y As Integer = 0 To 8 
     privateImage.Add(y.ToString + ".jpg") 
    Next 
End Sub 


Private Function GetListOfImages() As List(Of String) 
    Dim images = New List(Of String)() 

    If Session("Mode") = "Public" Then 
     Me.Title = "Public Image Gallery" 

     For Each s As String In publicImage 
      images.Add(String.Format("{0}/{1}", publicPath, s)) 
     Next 
    ElseIf Session("Mode") = "Private" Then 
     Me.Title = "Public Image Gallery" 

     For Each s As String In privateImage 
      images.Add(String.Format("{0}/{1}", privatePath, s)) 
     Next 
    End If 

    Return images 
End Function 


''' <summary> 
''' Binds the ImageListView to current DataSource 
''' </summary> 
Private Sub BindData() 
    ImageListView.DataSource = GetListOfImages() 
    ImageListView.DataBind() 

    Me.DataPager1.Visible = Me.DataPager1.PageSize < Me.DataPager1.TotalRowCount ' Don't show datapager if it only has one page 
End Sub 

Protected Sub lbPublic_Click(sender As Object, e As EventArgs) Handles lbPublic.Click 
    Session("Mode") = "Public" 
End Sub 

Protected Sub lbPrivate_Click(sender As Object, e As EventArgs) Handles lbPrivate.Click 
    Session("Mode") = "Private" 
End Sub 


End Class 

WebForm1.aspx를

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="datasourcenotupdating.WebForm1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <link href="StyleSheet1.css" rel="stylesheet" type="text/css" /> 
</head> 
<body>  
<form id="form1" runat="server"> 
    <div class="divWrapper"> 
     <div class="link"> 
      <asp:LinkButton ID="lbPublic" runat="server" Text="Public" ClientIDMode="Static" /> 
       &nbsp; 
      <asp:LinkButton ID="lbPrivate" runat="server" Text="Private" ClientIDMode="Static" /> 
     </div> 
     <asp:ListView ID="ImageListView" runat="server"> 
      <LayoutTemplate> 
       <ul class="ImageListView"> 
        <asp:PlaceHolder runat="server" ID="itemPlaceholder" /> 
       </ul> 
      </LayoutTemplate> 
      <ItemTemplate> 
       <li style="margin-left: 0px;"> 
        <a class="photo" href="#"> 
         <asp:Image ID="thumbnail" runat="server" Height="128" Width="128" ImageUrl='<%# Container.DataItem %>' /> 
        </a> 
       </li> 
      </ItemTemplate> 
      <EmptyItemTemplate> 
       <div> 
        Sorry! No image found. 
       </div> 
      </EmptyItemTemplate> 
     </asp:ListView> 
     <div style="width:300px; margin:0 auto;"> 
      <table class="tblMain" style="width: 100%; border-collapse: collapse;"> 
       <tr> 
        <td> 
         <div class="datapager"> 
          <asp:DataPager ID="DataPager1" PageSize="45" PagedControlID="ImageListView" runat="server" ClientIDMode="Static"> 
           <Fields> 
            <asp:NumericPagerField /> 
           </Fields> 
          </asp:DataPager>  
         </div> 
        </td> 
       </tr>      
      </table> 
     </div>  
    </div> 
</form> 
</body> 
</html> 

StyleSheet1.css

.divWrapper{ 
margin:80px 50px 0px 50px; 
position: relative; 
} 
.divWrapper a img{ 
border:none; 
} 
.divWrapper ul{ 
list-style:none; 
padding-bottom:20px; 
float:left; 
} 
.divWrapper ul li{ 
position:relative; 
text-align:center; 
float:left; 
margin:3px; 
background-color:#121212; 
width:180px; 
height:140px; 
border:1px solid #292929; 
-moz-border-radius:5px; 
-webkit-border-radius:5px; 
border-radius:5px; 
} 
.divWrapper ul li a{ 
display:table-cell; 
text-align:center; 
vertical-align:middle; 
width:180px; 
height:140px; 
outline:none; 
-moz-border-radius:5px; 
-webkit-border-radius:5px; 
border-radius:5px; 
-moz-box-shadow:0px 0px 3px #000 inset; 
-webkit-box-shadow:0px 0px 3px #000 inset; 
box-shadow:0px 0px 3px #000 inset; 
} 
.divWrapper ul li a:hover{ 
background-image:none; 
} 
.divWrapper ul li a img{ 
vertical-align:middle; 
border:1px solid #222; 
opacity:0.6; 
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=60); 
-moz-box-shadow:1px 1px 3px #000; 
-webkit-box-shadow:1px 1px 3px #000; 
box-shadow:1px 1px 3px #000; 
} 
.divWrapper ul li a.photo{ 
background:transparent url(../images/photo.png) no-repeat top right; 
} 
+0

왜 '_PreRender'에서 작업하고 있습니까? –

+0

ASP .NET 수명주기를 기반으로 데이터 바인딩을 수행하기에 좋은 곳입니다. – user3585893

답변

0

는 startRowIndex 이전 데이터 소스의 값을 유지하는있는 DataPager를 해제합니다. 목록보기의 항목 수가 이전 항목보다 적을 경우이 값을 업데이트해야합니다. 세션 변수를 생성하여 다른 데이터 소스 datapager startRowIndex를 추적하거나 다음과 같이 첫 번째 페이지로 리셋 할 수 있습니다.

Protected Sub lbPublic_Click(sender As Object, e As EventArgs) Handles lbPublic.Click 
    Session("Mode") = "Public" 
    Me.DataPager1.SetPageProperties(0, me.DataPager1.maximumRows, False) 
End Sub 

Protected Sub lbPrivate_Click(sender As Object, e As EventArgs) Handles lbPrivate.Click 
    Session("Mode") = "Private" 
    Me.DataPager1.SetPageProperties(0, me.DataPager1.maximumRows, False) 
End Sub