0

I saw several posts regarding this topc. I noticed one code. I also worked on the same code n the below code url . 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>

How can I bind using ajax and jquery. My page takes 16 seconds to load the page. That's y i am going for jquery.

Please help me for finding solution....

Thanks

3
  • How much data is being binded to the drop down list ? Commented Feb 2, 2013 at 10:21
  • almost 500 rows. I want to bind to datalst. and the datalist is well formated... Commented Feb 2, 2013 at 10:24
  • I am using datalst as <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> Commented Feb 2, 2013 at 10:28

2 Answers 2

1

You will not be able to Bind a DataList control via jQuery because the control is only created when bound through server side code, e.g. on the code behind.

If you are wanting to use Ajax and jQuery to bind controls, then you would be better of using plain old HTML.

Alternatively, bind the DataList with some data so that it is rendered, and then the HTML elements will be created on the page and you can work with them.

Sign up to request clarification or add additional context in comments.

3 Comments

"Alternatively, bind the DataList with some data so that it is rendered, and then the HTML elements will be created on the page and you can work with them"
How it is possible using html elements...? can you provide me any sample codes...?
Was going to post an example but got side tracked.
0

I implemented this concept without postback using callback methods. the code is given below

 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

thanks all for your help....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.