+ Reply to Thread
Results 1 to 5 of 5

Thread: Retrieving DataItem on Postback

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Retrieving DataItem on Postback

    I'm seeing if I can retrieve a DataItem from a datalist when I postback data. I want to retrieve an item of data from each row that was bound to the datalist.

    I have tried this code, but it gives an error:-
    Code:
    For each item as DataListItem in dlst_policies.items
        update_error.text =item.DataItem("policyref") & "<br />"
    next
    
    update_error is just a literal control on my page.

    The error I get is:-
    Object variable or With block variable not set.

    As the datalist contains a List Of a class of mine, I've also tried
    Code:
    For each item as DataListItem in dlst_policies.items
        Dim comm As PolicyPremiumBOL = item.DataItem
        update_error.text = comm.policyref & "<br />"
    next
    
    But then I get an Object reference not set to an instance of an object error.

    Is it possible to retrieve the data items when you're posting back or would I need to include a hidden field control or something that contains the data I want?

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    For your first error: Object variable or With block variable not set

    For the second problem...are you using one of the DataList events during the postback? DataList Events

    And the correct way, would be something like:

    Code:
    For each item as DataListItem in dlst_policies.items
        Dim comm As PolicyPremiumBOL = CType(item.DataItem, PolicyPremiuBOL)
        update_error.text = comm.policyref & "<br />"
    Next
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I just put in a hidden field containing the reference I needed.

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by richyrich View Post
    I just put in a hidden field containing the reference I needed.
    quit taking the easy way...go the .Net way
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    quit taking the easy way...go the .Net way
    I will try what you suggested, just needed to get that done quickly and move on to something else...

+ Reply to Thread

Similar Threads

  1. Retrieving Web Data using Excel
    By mehere in forum Microsoft Office
    Replies: 13
    Last Post: May 22nd, 2008, 04:14 PM
  2. Finding Datalist Row on auto postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: May 12th, 2008, 05:52 AM

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

SEO by vBSEO