SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use jQuery to Convert ASP.NET ListView Contents to JSON String

    I have an ASP.NET ListView. Via ItemTemplate it renders as a table with columns ID and Name, and three rows of sample data:


    ID | Name

    1 | Name1

    2 | Name2

    3 | Name3


    The data cells (i.e., 1, Name1, etc.) are all ASP.NET TextBoxes. In other words HTML inputs.

    Is there a convenient, or at least most convenient, jQuery method for extracting the values from these data cells and packaging them into a JSON array that is sent AJAX-style to the server?

    If it's not too much trouble I'd also really appreciate advice on how to add a row to the ListView without a postback.

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    47 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Well the only option you really have is to create a foreach loop and loop through each textbox yourself and append it to a string, and that string should be in JSON format when done. So it is a rather manual process.

    As for adding an item with jquery, what you would need to do here is inspect the output of your listview as html. This will depend on your template, etc. But you mentioned a table, so I am going with that. You will need to replicate the item template in your script. Then using jQuery to target that table and append the html you created into the table.

  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Is there any chance you have a useful link for how to write this loop logic in jQuery?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •