2013-02-02 113 views
0

我看到了幾篇關於這個topc的文章。我注意到一個代碼。我也在下面的代碼url中使用了相同的代碼。 Binding asp.net datalist with jQuery用jQuery綁定asp.net datalist不起作用

function OnSuccess(response) { 
      $("[id*=dlOnFrontPageProducts]").attr("border", "1"); 
      var xmlDoc = $.parseXML(response.d); 
      var xml = $(xmlDoc); 
      var customers = xml.find("Table1"); 
      var row = $("[id*=dlOnFrontPageProducts] tr:last-child").clone(true); 
      $("[id*=dlOnFrontPageProducts] tr:last-child").remove(); 
      $.each(customers, function() { 
       alert(this); 
       var customer = $(this); 
       $(".Name", row).html(customer.find("Name").text()); 
       $(".BrandName", row).html(customer.find("BrandName").text()); 
       $(".MarketPrice", row).html(customer.find("MarketPrice").text()); 
       $(".CurrencyShortName", row).html(customer.find("CurrencyShortName").text()); 
       $(".Price", row).html(customer.find("Price").text()); 
       $(".WindowImageUrl", row).html(customer.find("WindowImageUrl").text()); 
       $(".SaleCount", row).html(customer.find("SaleCount").text()); 
       $(".IsActive", row).html(customer.find("IsActive").text()); 
       $("[id*=dlOnFrontPageProducts]").append(row); 
       row = $("[id*=dlOnFrontPageProducts] tr:last-child").clone(true); 
      }); 
     } 




<asp:DataList ID="DataList1" runat="server" AutoGenerateColumns="false" Font-Names="Arial" 
Font-Size="10pt" RowStyle-BackColor="#A1DCF2" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor = "White"> 
    <ItemTemplate> 
    <asp:Label ID="lbldescription" runat="server" Text='<%# Eval("description")%>'> 
     </asp:Label> 
    <asp:Label ID="name" runat="server" Text='<%# Eval("name")%>'> 
     </asp:Label>     
    </ItemTemplate> 

我如何結合使用AJAX和jQuery。我的頁面需要16秒來加載頁面。這是我要去jquery。

請幫我尋找解決方案....

感謝

+0

有多少數據被綁定到下拉列表下面的代碼給出? – Nikshep

+0

差不多500行。我想綁定到datalst。並且datalist格式正確... –

+0

我正在使用datalst作爲

回答

1

您將無法Bind通過jQuery一個DataList控制,因爲通過服務器端代碼,例如結合時才創建控件關於後面的代碼。

如果您想要使用Ajax和jQuery控制bind,那麼您最好使用普通的舊HTML。

或者,將DataList與某些數據綁定以便渲染它,然後在頁面上創建HTML元素,並且可以使用它們。

+0

「或者,將DataList與某些數據綁定以便渲染,然後將在頁面上創建HTML元素,並且您可以使用他們「 –

+0

如何使用html元素...?你能給我提供任何示例代碼嗎? –

+0

給我一分鐘左右 –

0

我實現了這個概念,沒有使用回調方法回發。

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



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) 
    gvCustomers.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) 


    gvCustomers.DataSource = dt 
    gvCustomers.DataBind() 
    SearchTextBox.Focus() 


End Function 

感謝所有您的幫助....