2013-02-04 74 views
0

我在回調事件上綁定了datalist。點擊數據列表中的按鈕需要回傳以獲取另一個數據列表的數據。但在回發後,頁面上不會顯示任何數據專家。我不知道回發上發生了什麼。請幫我尋找解決....由回調事件創建的datalist在回發中丟失

If IsPostBack = False Then 
     callback = ClientScript.GetCallbackEventReference(Me, "message", "processMyResult", "context") 
     Dim script As String = "function CallBack(message,context){" + callback + ";}" 
     ClientScript.RegisterClientScriptBlock(Me.GetType(), "CB", script:=script, addScriptTags:=True) 


     callbackhotelsearch = ClientScript.GetCallbackEventReference(Me, "message", "processhotelsearchResult", "context") 
     Dim scriptsearch As String = "function callbackhotelsearch(message,context){" + callback + ";}" 
     ClientScript.RegisterClientScriptBlock(Me.GetType(), "CB", script:=scriptsearch, addScriptTags:=True) 

     SearchTextBox.Attributes.Add("onkeyup", "javascrpt:LookUpStock()") 
     SearchTextBox.Attributes.Add("onfocus", "javascript:SetCursorToTextEnd()") 
    End If 





Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent 

    If (eventArgument) Is Nothing Then 

     returnValue = "-1" 

    Else 

     binddata(eventArgument) 
    End If 



    Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder() 
    Dim sw As System.IO.StringWriter = New System.IO.StringWriter(sb) 
    Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) 
    dataListPackages.RenderControl(hw) 
    returnValue = sb.ToString() 

End Sub 

Public Function GetCallbackResult() _ 
As String Implements _ 
System.Web.UI.ICallbackEventHandler.GetCallbackResult 

    Return returnValue 

End Function 

Public Function binddata(ByVal eventArgument As String) As Nullable 
    Dim adp As New dsRegistrationTableAdapters.searchPackagesTableAdapter() 
    Dim dt As New dsRegistration.searchPackagesDataTable() 
    dt = adp.GetData(eventArgument, StartDateTextBox.Text, EndDateTextBox.Text) 
    'StartDateTextBox.Text = "11-12-2012" 

    dataListPackages.DataSource = dt 
    dataListPackages.DataBind() 
    SearchTextBox.Focus() 
    Return Nothing 
End Function 

謝謝

+0

可以請你在這裏發佈你的代碼嗎? – Prashant16

+0

希望你知道你必須在每次回發或頁面刷新後綁定數據列表。 – Vishal

+0

我已經發布了代碼。我不知道綁定dattalist在每個回發...是因爲回調事件綁定? –

回答

1

數據源項目不是初始加載後進行訪問。它們僅在數據綁定中可用。

對於您的情況,您可以使用HiddenField在發佈期間存儲ID,然後通過該ID而不是dataitem獲取數據,因爲回發後dataitem不會可用。

+0

但我綁定了一個按鈕上的下一個datalist單擊數據列表中的動作。這一次,所有的細節都在第一位datalist上丟失了。 –