473,761 Members | 9,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1684
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********@dis cussions.micros oft.com> wrote in message
news:52******** *************** ***********@mic rosoft.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
2400
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: http://www.dotnetbips.com/displayarticle.aspx?id=205 If I bind the datagrid to the dataset at all times, whether Postback or not, then everything works fine. However if I only bind it when Page is not Postback (just like
18
2453
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 textbox, and in the second row I need to bind data into a dropdownlist...It all depends on the data I select from the database. I cannot use TemplateColumn because it has to be the same type of control for one column.
5
1474
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 sets it up previously). The questions are in a db. Is a datagrid the best way to display this data? What do you suggest? After they enter the info I want to be able to save it back to the db. Any helpful links/examples?
2
5928
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 the look-up-table with textboxes. I have a linkbutton in each row (causevalidation = false) named 'Edit' to post the page back such that the page is switch from display mode to edit mode (labels -> textboxes for the row to be edited), and the...
2
2220
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 the 26 letters of the alphabet as hyperlinks which the users then click to return records beginning with that letter, displayed in a DataGrid. The first column of the DataGrid contains a LinkButton which, when clicked, calls the Delete method of...
9
6105
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 searching the columnheader text, but found that AutoGenerated columns are members of the Columns collection. From the msdn documentation: Note: When the AutoGenerateColumns property is set to true, the columns created by the DataGrid control are...
3
1711
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 Template Columns, into which I put buttons. When the user clicks on the 'Do It' button, the selection is recorded in an underlying database, and (almost) everything is fine. One thing I would like to improve in the existing version concerns...
2
6252
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 that enables the items -- this works perfectly. However, when I then click a LinkButton that does a postback and I loop through the items on serverside to pick up the selected ones, it doesn't pick them up. IMHO it seems to loop though the items...
9
2727
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
9376
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9988
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.