473,418 Members | 2,075 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,418 software developers and data experts.

Looping over a DataGrid after postback; questions

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
2 1671
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruce W.1 | last post by:
There's something I can't figure out. I added some javascript behavior to my datagrid, just like in this article, except in C# instead of VB: ...
18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
5
by: VB Programmer | last post by:
I have an ASP.NET form that allows people to answer survey questions. There could be from 5 to an unlimited amt of questions, depending on which questions the admin wants to users to answer (he...
2
by: Fluxray | last post by:
--Background: I have a webform including a datagrid. The datagrid is using template. Its ItemTemplate is used to display a look-up-table with labels. its EditItemTemplate is used to edit a row in...
2
by: Mark Rae | last post by:
I've inherited an ASP.NET app and have been asked to fix the following problem with a page which is used to display and/or delete records from a database. When the page loads, it displays a list of...
9
by: Steve | last post by:
How I can remove an AutoGenerated column? I wnat to inlcude the primary key in the resultset for creating some custom LinkButtons, but I don't want it (the PK) displayed in the DataGrid. I tried...
3
by: Phillip N Rounds | last post by:
I have a DataGrid in a web form (ASP1.1, C#, VS 2003) that I'm trying to add some functionality to, and I can't figure out how to do int. The existing DataGrid has several databound columns and a...
2
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.