0

我看到了几个关于这个话题的帖子。我注意到一个代码。我还在下面的代码 url 上处理了相同的代码。 用 jQuery 绑定 asp.net 数据列表

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。

请帮助我找到解决方案....

谢谢

4

2 回答 2

1

您将无法Bind通过DataListjQuery 控制控件,因为该控件仅在通过服务器端代码绑定时创建,例如在后面的代码上。

如果您想使用 Ajax 和 jQuery 来bind控制,那么您最好使用普通的旧 HTML。

或者,将DataList与一些数据绑定以便呈现,然后将在页面上创建 HTML 元素,您可以使用它们。

于 2013-02-02T10:24:10.037 回答
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

感谢你的帮助....

于 2013-02-03T13:39:31.717 回答