DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Retrieving DataItem on Postback

This is a discussion on Retrieving DataItem on Postback within the .Net Development forums, part of the Programming & Scripting category; I'm seeing if I can retrieve a DataItem from a datalist when I postback data. I want to retrieve an ...

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

  #1  
Old July 21st, 2008, 08:59 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,345
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default 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?
Reply With Quote
  #2  
Old July 21st, 2008, 09:23 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

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 with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

Reply With Quote
  #3  
Old July 21st, 2008, 10:02 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,345
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

I just put in a hidden field containing the reference I needed.
Reply With Quote
  #4  
Old July 21st, 2008, 10:13 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

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
Reply With Quote
  #5  
Old July 21st, 2008, 10:15 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,345
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Retrieving Web Data using Excel mehere Microsoft Office 13 May 22nd, 2008 03:14 PM
Finding Datalist Row on auto postback richyrich .Net Development 1 May 12th, 2008 04:52 AM


All times are GMT -4. The time now is 05:15 PM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2