用jQuery绑定asp.net datalist是行不通的

时间:2013-02-02 10:19:16

标签: asp.net jquery

我看了几篇关于这个topc的帖子。我注意到一个代码。我也在下面的代码网址上使用相同的代码。 Binding asp.net datalist with jQuery

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。

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

由于

2 个答案:

答案 0 :(得分:1)

您将无法通过jQuery Bind DataList控件,因为控件仅在通过服务器端代码绑定时创建,例如:关于背后的代码。

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

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

答案 1 :(得分: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

感谢所有人的帮助......