【问题标题】:After Download zip file datalist is not Bind下载 zip 文件后 datalist 未绑定
【发布时间】:2013-08-26 01:54:25
【问题描述】:

下面是我在按钮搜索上的代码我需要绑定我的网格并下载 zip 文件问题是下载了 zip 文件但我的网格没有调用绑定函数但 datalist 没有绑定

Private Sub BindGrid()
    SQL = "Select JameatID,JamaatID,MadrassahID, JameatName,JamaatName,MadrassahName,StudentID,ClassID,DIvisionName,FullName,datediff (year ,DOB,getdate() )as Age  from vwstudent vw LEFT OUTER JOIN CMaster cm ON vw.ClassID =cm.CMID AND MasterName ='ClassID'  where 1=1   order by JameatName,JamaatName,MadrassahName,cm.OrderId "
    Dim ds As New dataset
    ds = gc.GetDataToListBinder(SQL)
    DListPhotoInfo.DataSource = ds 
    DListPhotoInfo.DataBind()

End Sub

Private Sub DownloadImage(ByVal EJID As String)
    Dim DS As Data.DataSet
    Dim tmpZipFile As String
    tmpZipFile = System.IO.Path.GetTempFileName
    Dim zipFile As New GraficaliZip(tmpZipFile)
    zipFile.CreateZipFile()
    Dim strID() As String = Split(EJID.Trim, ",")
    For i As Integer = 0 To strID.Length - 1
         If ImageExist(strID(i).Trim) = True Then
             zipFile.PutFile(Server.MapPath(".") & _
                             "\Photo\" & strID(i).Trim & _
                             ".jpg", strID(i).Trim & ".jpg")
         End If
     Next
       BindGrid() ///from here i am binding grid
     zipFile.SaveFile()
     gc.DownLoadFileFromServer("", tmpZipFile & ".zip", "Photo.zip")
End Sub

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click


    DownloadImage("20312059,20313178")
    PnlGrid.Visible = True
End Sub

【问题讨论】:

  • 你能把BindGrid()函数的代码也包括进来吗?
  • 我更新了 bindgrid 的代码,请参考
  • 可能是其他代码破坏了 DataList。所以...尝试将断点@BindGrid() 方法的最后一行。确认获取的数据并正确绑定到 DataList。然后一步步往前走,在DataList正确绑定后,检查哪部分代码干扰了DataList。

标签: asp.net vb.net sql-server-2005 visual-studio-2008


【解决方案1】:

在 pageLoad 事件中调用 !IsPostBack 内的 BindGrid() 方法

对于

Page_load()
{
 if(!IsPostBack)
 {
 BindGrid()
 }    
}

您还需要在下载按钮点击事件中调用 BindGrid() 方法

Private Sub DownloadImage(ByVal EJID As String)
    Dim DS As Data.DataSet
    Dim tmpZipFile As String
    tmpZipFile = System.IO.Path.GetTempFileName
    Dim zipFile As New GraficaliZip(tmpZipFile)
    zipFile.CreateZipFile()
    Dim strID() As String = Split(EJID.Trim, ",")
    For i As Integer = 0 To strID.Length - 1
         If ImageExist(strID(i).Trim) = True Then
             zipFile.PutFile(Server.MapPath(".") & _
                             "\Photo\" & strID(i).Trim & _
                             ".jpg", strID(i).Trim & ".jpg")
         End If
     Next
     zipFile.SaveFile()
     gc.DownLoadFileFromServer("", tmpZipFile & ".zip", "Photo.zip")
 **BindGrid()**
End Sub

更新

先调用下载方法,再点击搜索按钮时调用绑定方法

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click


    DownloadImage("20312059,20313178")
 **BindGrid()**
    PnlGrid.Visible = True
End Sub

编辑: 如果你使用更新面板,那么

在调用BindGrid()后调用UpdatePanelID.Update()

  • UpdatePanel 控件嵌套在另一个UpdatePanel 控件中并且父面板更新时。

更多问题:

看看这个链接的

http://forums.asp.net/t/1605207.aspx

Update Datalist in UpdatePanel

http://forums.asp.net/t/1320236.aspx/1?update+panel+doesnot+refresh+the+datalist+control+for+first+time

【讨论】:

  • 请再看一次我的回答。
  • 下载 zip 文件后如何更新数据列表。更新面板也不会刷新我的数据列表。
  • malummaaat nahi 数据列表不刷新
  • 需要帮助来刷新我的数据列表
  • DownloadImage("20312059,20313178") BindGrid() PnlGrid.Visible = True 我也在做同样的事情,但不工作
猜你喜欢
  • 1970-01-01
  • 2013-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多