473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

GridView, converting to object

Hi
I have a gridview on my web page and I bind it to an object of my own
creation. When I click a button on that page, I want to get the data
from that gridview and cast it back into that object I created and
start to do work on it. I tried something like this:

List<MyObjectmyObject = (List<MyObject>)myGrid.DataSource;
But I noticed that when I get to this line, "myGrid.DataSource" is
null. Yet, I can access the "myGrid.Rows.Count" value and see the
correct number of rows in my grid.
How can I convert to my own object?

Jul 25 '07 #1
3 1874
I'm afraid your original data source is gone after postback. The grid
serializes its data in ViewState by default so you don't necessarily have to
rebind after every postback, so that gives the illusion that your original
data source is still there - but it's not.
If you want your original data source object then you'll have to manually
store it between postbacks or requery your data source after the postback.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

"Doogie" <dn******@dtgnet.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi
I have a gridview on my web page and I bind it to an object of my own
creation. When I click a button on that page, I want to get the data
from that gridview and cast it back into that object I created and
start to do work on it. I tried something like this:

List<MyObjectmyObject = (List<MyObject>)myGrid.DataSource;
But I noticed that when I get to this line, "myGrid.DataSource" is
null. Yet, I can access the "myGrid.Rows.Count" value and see the
correct number of rows in my grid.
How can I convert to my own object?
Jul 25 '07 #2
I'm afraid your original data source is gone after postback.
I hope this helps,
Well, it helps but it's not what I was looking for. :) So I'm
assuming my best option is to store the data in a Session object and
then pull it out when needed?

Jul 25 '07 #3
yes. also you should turn off view state on the grid and re-databind on
postback.

-- bruce (sqlwork.com)

Doogie wrote:
>I'm afraid your original data source is gone after postback.
>I hope this helps,

Well, it helps but it's not what I was looking for. :) So I'm
assuming my best option is to store the data in a Session object and
then pull it out when needed?
Jul 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: | last post by:
Hello, I am trying to get add a product to a cart from a gridview control when a button in the gridview is clicked. I have a book on how to do this in asp.net 2.0 but it is done by specifying...
1
by: SDRoy | last post by:
Hi I am using asp:BoundField code for my GridView Control. Something like: <asp:GridView ID="GridView2" runat="server" AutoGenerateEditButton="True" OnRowEditing="GridView2_RowEditing"> ...
5
by: BenG | last post by:
Hi. I have a gridview control on a web form (asp.net 2.0) that's bound to a objectDataSource. The objectdatasource which is bound to a class I've written in the DAL to read and update the database....
2
by: Keithb | last post by:
I need to hide a GridView's "edit" column if the user's role does not support editing. However, the column's Visible property does not support databinding. Is there a workaround? Thanks, ...
2
by: rodchar | last post by:
hey all, you know in the gridView quick task menu how you have the option of taking a bound column and converting it into a TemplateColumn. Alright, once i do that i goto edit the template column...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
2
by: rgparkins | last post by:
So, I've bitten the bullet and am converting some of my asp.net 1.1 sites to asp.net 2.0, now after many issues I have come to a stop with the objectdatasource and gridviews and maybe someone can...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.