By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,199 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,199 IT Pros & Developers. It's quick & easy.

Looping over a DataGrid after postback; questions

P: n/a
This may be a no-brainer, but I'm sure I follow what's happening here...

I have a DataGrid with one DropDownList per row. If I select a few DropDown
items and postback my page, I can't loop through the DataGridItems unless I
rebind my DataGrid. By "can't loop," I mean it's a mighty quick run
through-- zero iterations.

I was wondering...do I have to rebind on postbacks? If so, what happens if
I bind the DataGrid to a different set of data (same datasource and table
let's pretend, but different rows returned) on the postback? I tried it and
my DropDowns looked pretty... strange afterwards. Duplicates and such.
Hard to describe but it was surreal.

In scouring my brain I think there are some caveats about databinding on
postbacks? I could be wrong but are there specific gotchas I should be
aware of? Thanks for your help.
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
There is no need to databind your datagrid to iterate it. The datagrid will
be maintained through viewstate with default settings (viewstate enabled).
And hence you can iterate it.

Post your code for more specific details.

--
Cheers,
Rahul Anand

"Jim Bancroft" wrote:
This may be a no-brainer, but I'm sure I follow what's happening here...

I have a DataGrid with one DropDownList per row. If I select a few DropDown
items and postback my page, I can't loop through the DataGridItems unless I
rebind my DataGrid. By "can't loop," I mean it's a mighty quick run
through-- zero iterations.

I was wondering...do I have to rebind on postbacks? If so, what happens if
I bind the DataGrid to a different set of data (same datasource and table
let's pretend, but different rows returned) on the postback? I tried it and
my DropDowns looked pretty... strange afterwards. Duplicates and such.
Hard to describe but it was surreal.

In scouring my brain I think there are some caveats about databinding on
postbacks? I could be wrong but are there specific gotchas I should be
aware of? Thanks for your help.

Nov 19 '05 #2

P: n/a
Thanks-- I don't have the page viewstate enabled, in fact. I didn't want
the overhead. Oops.

If I were to enable the viewstate, what would happen if I rebound my
DataGrid after a postback? I assume that action would "overrule" the
viewstate's copy of the data, and I'd be looping through the new data?

I ask because my goal is to submit the form, loop through all the DropDowns
in the DataGrid, update my datasource, then reload the DataGrid from that
datasource. I'm not sure what the best sequence of events would be to
accomplish this. If anyone knows I'd be grateful. Thanks again.

-Jim


"Rahul Anand" <Ra********@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
There is no need to databind your datagrid to iterate it. The datagrid will be maintained through viewstate with default settings (viewstate enabled).
And hence you can iterate it.

Post your code for more specific details.

--
Cheers,
Rahul Anand

"Jim Bancroft" wrote:
This may be a no-brainer, but I'm sure I follow what's happening here...

I have a DataGrid with one DropDownList per row. If I select a few DropDown items and postback my page, I can't loop through the DataGridItems unless I rebind my DataGrid. By "can't loop," I mean it's a mighty quick run
through-- zero iterations.

I was wondering...do I have to rebind on postbacks? If so, what happens if I bind the DataGrid to a different set of data (same datasource and table let's pretend, but different rows returned) on the postback? I tried it and my DropDowns looked pretty... strange afterwards. Duplicates and such.
Hard to describe but it was surreal.

In scouring my brain I think there are some caveats about databinding on
postbacks? I could be wrong but are there specific gotchas I should be
aware of? Thanks for your help.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.