Is there a workaround for datagrid contents being lost on postback?
All other controls persist. It's just datagrids that appear to be
reinitialized.
It doesn't make sense to continually rebuild datagrids on postback when
other controls don't require it.
Thanks in advance. 10 2669
Hi,
you need to show (code) how it is used. Otherwise it is bit hard to help
you.
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU http://blogs.aspadvice.com/joteke
"Jeff" <jd****@bigfoot.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com... Is there a workaround for datagrid contents being lost on postback? All other controls persist. It's just datagrids that appear to be reinitialized. It doesn't make sense to continually rebuild datagrids on postback when other controls don't require it.
Thanks in advance.
You've probably disabled viewstate so that you have to rebind (not
rebuild) your datagrid. That is very common and there's nothing wrong
with it. Unless you want to turn viewstate on and have a huge
viewstate.
Other controls dont' require it because they are using form field data
to repopulate. The datagrid can't do that.
I dont' know if this is what your question means.
-Sam
Possibilities:
1. ViewState of the datagrid is disabled (unlikely)
2. DataBinding of the datagrid occurring at every page load (and not in the
initial load) (very likely)
"Jeff" <jd****@bigfoot.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com... Is there a workaround for datagrid contents being lost on postback? All other controls persist. It's just datagrids that appear to be reinitialized. It doesn't make sense to continually rebuild datagrids on postback when other controls don't require it.
Thanks in advance.
sam wrote: You've probably disabled viewstate so that you have to rebind (not rebuild) your datagrid. That is very common and there's nothing wrong with it. Unless you want to turn viewstate on and have a huge viewstate.
Other controls dont' require it because they are using form field data to repopulate. The datagrid can't do that.
I dont' know if this is what your question means.
-Sam
sam wrote: You've probably disabled viewstate so that you have to rebind (not rebuild) your datagrid. That is very common and there's nothing wrong with it. Unless you want to turn viewstate on and have a huge viewstate.
Other controls dont' require it because they are using form field data to repopulate. The datagrid can't do that.
I dont' know if this is what your question means.
-Sam
Thanks Sam for the input. Tried turning viewstate on and off and same
problem. Code is significant so I didn't include it. Tried
initializing datagrid on page load with no avail. Still resets.
Something funny, one column is still populated. All others are
cleared.
Thanks again for your quick response.
My code is basically this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack() Then
'POPULATE THE DROPDOWN LISTS
Dim pdmWS As pdmUsers.pdmUsersV1R0 = New
pdmUsers.pdmUsersV1R0
sXML = pdmWS.GetMyDatabases(ErrorCode, ErrorMsg)
CreateCheckBoxLists(sDSN)
InitializeDatagrid()
dgResults.Visible = True
Else '(POSTBACK)
dgResults.Visible = False
If Not Request.Form("btnSave") Is Nothing Then
Dim pdmAdminWS As pdmAdmins.pdmAdminsV1R0 = New
pdmAdmins.pdmAdminsV1R0
'loop throught data grid returned results to update database
For i = 0 To Request.Form.Count - 1
If Request.Form.Keys(i) Like "*dgResults*_DSN:*_DOC:*" Then
If pdmAdminWS.AddCatDocXref(ErrorCode, ErrorMsg,
....) Then
lblErrorMsg.Text = "Update Successful "
Else
lblErrorMsg.Text = ErrorCode & ": " & ErrorMsg
End If
End If
Next
'data grid is initialized here
dgResults.Visible = True
End If
If Not Request.Form("btnSubmit") Is Nothing Then
Dim pdmWS As pdmUsers.pdmUsersV1R0 = New
pdmUsers.pdmUsersV1R0
sXML = pdmWS.Search(ErrorCode, ErrorMsg, ...)
If ErrorCode = 0 Then
doc.LoadXml(sXML)
Dim reader As New XmlNodeReader(doc)
Dim ds As New DataSet
ds.ReadXml(reader)
reader.Close()
' FOUND SOME RESULTS
If (ds.Tables.Count > 0) Then
addChkBoxCol(dgResults) ' Adds checkbox to
datagrid
dgResults.DataSource = ds.Tables(0).DefaultView
dgResults.DataBind()
dgResults.Visible = True
End If
End If
End If
End Sub
Thank you so much for your assistance.
I've initialized the grid in the page load with a dummy row. Displays
nicely.
Tried viewstate on and off. No difference.
Thank you kindly for your assistance!
Is autogeneratecolumns set to false?
I hd a similar problem, and it turned out that, if this is set to
false, then you need to setup the columns (not the actual data binding)
on every page load (preferably during the init phase) am*********@gmail.com wrote: Is autogeneratecolumns set to false? I hd a similar problem, and it turned out that, if this is set to false, then you need to setup the columns (not the actual data binding) on every page load (preferably during the init phase)
Thanks for the quick input. Interesting!
I'm curious how you set up the columns without binding the grid since
the datasource is lost on postback? The grid has AutoGenerateColumns =
false.
Thank you again.
Well, if you have viewstate enabled, (i guess i shud hv asked this
earlier)
the data in your datagrid is all saved, but since the autogenerate
columns is false (columns were generated first time, when you did the
data binding), you dont see anything in ur grid
Now on the page postback, the data is still there (assuming viewstate
is enabled) but the column information is not saved, so you set the
columns again. The way I do it is as below
Page_Init()
{
// set up the column 1
BoundColumn obc = new BoundColumn();
obc.HeaderText = sHeaderText;
obc.DataField = sColumnName;
DataGrid1.Columns.Add(obc);
// similarly setup all the other columns
....
}
Page_Load()
{
If (! postback)
{
ds = some query
DataGrid1.dataSource = ds
DataGrid1.DataBind()
}
}
hope this helps This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michelle Stone |
last post by:
Hi all. I have an empty datagrid on my web form. And I
add BoundDataColumn(s) to it through code. But after each
postback, the columns and rows disappear.
As a workabout, I tried to rebind the...
|
by: Allen K |
last post by:
Hi,
I'm programmatically creating a HyperLink column for my datagrd ( in
addition to Bound Columns created through the VS.NET Visual Interface ).
However, when a Postback occurs, this column...
|
by: wh1974 |
last post by:
I'm not sure if i'm heading in the right direction so would appreciate
any comments on what I'm trying to do.
Basically I have a DataGrid on a page which has columns whose width's I
set in the...
|
by: mwhalen |
last post by:
Hi,
I have a page that has a datagrid bound to a dataset. Items are added to
the dataset at particular times (ie the click event of an item in a tree
control) then bound to the grid. The grid...
|
by: Ken Varn |
last post by:
I have a problem where my DataGrid would not maintain the ViewState of my
databound rows. I finally narrowed down the problem. If my first column is
a template column, the view state for the...
|
by: Lyners |
last post by:
I have a web page writen in ASP.NET that contains some javascript so that
when a user presses a button, or edits a certain field in a datagrid, another
cell in the datagrid is filled with a value....
|
by: news.zen.co.uk |
last post by:
Hi Guys,
Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the...
|
by: rockdale |
last post by:
Hi, All:
I dynamic add an arrow up/down image in OnItemDataBound event for my
datagrid, it works fine. But I have another textbox which trigger
postback and doing something, after this event get...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |