473,511 Members | 15,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid Columns lost on Postback????

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 simply disappears, as if it
doesn't exist in ViewState.. However, the columns I created in the VS.NET
DataGrid editor appear just fine.. Can someone help me??

Heres my code:

private void Page_Load( object sender, System.EventArgs e )
{
HyperLinkColumn viewDetails = new HyperLinkColumn();

viewDetails.DataNavigateUrlField = UConst.COL_USERID;
viewDetails.DataNavigateUrlFormatString =
Constants.URL_VIEWUSER + "?userID={0}";

viewDetails.Text = "View Details";
viewDetails.HeaderText = "Details";

TemplateColumn vd = new TemplateColumn();

dgSearchResults.Columns.Add( viewDetails );

if( !IsPostBack )
{
Initialize();
//SetupDataGridColumns();
}

}

I've also tried adding this to the If( !IsPostBack ) block and that
doesn't seem to work either..

Any help would be much appreciated! Thanks!
Allen
Nov 18 '05 #1
3 2411
DataGrid Columns are not in ViewState!

If you add a column in codebehind you must readd this columns at all
postback.
The columns you created in the VS.NET DataGrid editor appear just fine
because are addedall the time when page is instanced!

Your code is ok!

Brun

"Allen K" <x******@hotmail.com> wrote in message
news:Xn*************************@198.161.157.145.. .
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 simply disappears, as if it
doesn't exist in ViewState.. However, the columns I created in the VS.NET
DataGrid editor appear just fine.. Can someone help me??

Heres my code:

private void Page_Load( object sender, System.EventArgs e )
{
HyperLinkColumn viewDetails = new HyperLinkColumn();

viewDetails.DataNavigateUrlField = UConst.COL_USERID;
viewDetails.DataNavigateUrlFormatString =
Constants.URL_VIEWUSER + "?userID={0}";

viewDetails.Text = "View Details";
viewDetails.HeaderText = "Details";

TemplateColumn vd = new TemplateColumn();

dgSearchResults.Columns.Add( viewDetails );

if( !IsPostBack )
{
Initialize();
//SetupDataGridColumns();
}

}

I've also tried adding this to the If( !IsPostBack ) block and that
doesn't seem to work either..

Any help would be much appreciated! Thanks!
Allen

Nov 18 '05 #2
OK that makes sense... But using the code below, I still can't seem to
make the column appear even though I re-add it every time the page posts
back?. If I rebind the datagrid each time then it seems to work fine, but
I should be able to do it without rebinding shouldn't I?

Allen

"Bruno Sirianni" <br***********@virgilio.it> wrote in
news:4S*********************@news3.tin.it:
DataGrid Columns are not in ViewState!

If you add a column in codebehind you must readd this columns at all
postback.
The columns you created in the VS.NET DataGrid editor appear just
fine because are addedall the time when page is instanced!

Your code is ok!

Brun

"Allen K" <x******@hotmail.com> wrote in message
news:Xn*************************@198.161.157.145.. .
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 simply disappears, as
if it doesn't exist in ViewState.. However, the columns I created in
the VS.NET DataGrid editor appear just fine.. Can someone help me??

Heres my code:

private void Page_Load( object sender, System.EventArgs e )
{
HyperLinkColumn viewDetails = new HyperLinkColumn();

viewDetails.DataNavigateUrlField = UConst.COL_USERID;
viewDetails.DataNavigateUrlFormatString =
Constants.URL_VIEWUSER + "?userID={0}";

viewDetails.Text = "View Details";
viewDetails.HeaderText = "Details";

TemplateColumn vd = new TemplateColumn();

dgSearchResults.Columns.Add( viewDetails );

if( !IsPostBack )
{
Initialize();
//SetupDataGridColumns();
}

}

I've also tried adding this to the If( !IsPostBack ) block and that
doesn't seem to work either..

Any help would be much appreciated! Thanks!
Allen



Nov 18 '05 #3
I figured out what the problem was. It turns out that the viewstate
information for the DataGrid is loaded in sometime between the Page_Init
and Page_Load, so if I wanted to recreate the columns on postback I had
to add the code to do it inside Page_Init instead of Page_Load..
Everything works fine now!

Allen K <x******@hotmail.com> wrote in
news:Xn*************************@198.161.157.145:
OK that makes sense... But using the code below, I still can't seem to
make the column appear even though I re-add it every time the page
posts back?. If I rebind the datagrid each time then it seems to work
fine, but I should be able to do it without rebinding shouldn't I?

Allen

"Bruno Sirianni" <br***********@virgilio.it> wrote in
news:4S*********************@news3.tin.it:
DataGrid Columns are not in ViewState!

If you add a column in codebehind you must readd this columns at all
postback.
The columns you created in the VS.NET DataGrid editor appear just
fine because are addedall the time when page is instanced!

Your code is ok!

Brun

"Allen K" <x******@hotmail.com> wrote in message
news:Xn*************************@198.161.157.145.. .
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 simply
disappears, as if it doesn't exist in ViewState.. However, the
columns I created in the VS.NET DataGrid editor appear just fine..
Can someone help me??

Heres my code:

private void Page_Load( object sender, System.EventArgs e )
{
HyperLinkColumn viewDetails = new HyperLinkColumn();

viewDetails.DataNavigateUrlField = UConst.COL_USERID;
viewDetails.DataNavigateUrlFormatString =
Constants.URL_VIEWUSER + "?userID={0}";

viewDetails.Text = "View Details";
viewDetails.HeaderText = "Details";

TemplateColumn vd = new TemplateColumn();

dgSearchResults.Columns.Add( viewDetails );

if( !IsPostBack )
{
Initialize();
//SetupDataGridColumns();
}

}

I've also tried adding this to the If( !IsPostBack ) block and that
doesn't seem to work either..

Any help would be much appreciated! Thanks!
Allen



Nov 18 '05 #4

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

Similar topics

1
1201
by: Demetri | last post by:
I have a datagrid on an aspx page with one column added via property builder - the edit/update/cancel. In addition there is a dropdownlist which has a list of table names. Upon selecting one of...
1
3419
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...
3
1328
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...
1
1625
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...
1
2680
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
10
2676
by: Jeff | last post by:
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...
4
1564
by: gh | last post by:
I create the columns for the asp.net datagrid at runtime and populates them. I have a template column for checkboxs I created at runtime as well. The user selects the product they want by...
1
1030
by: Reg | last post by:
Hello, I already posted a question about a problem with a datagrid. ("Lost columns in datagrid", thanks for JohnH) I dynamically create columns in a datagrid and the user selects lines (column...
9
2708
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
8192
by: abellix | last post by:
An updatepanel contains a datagrid, this datagrid has columns generated by code-behind: some columns should have async postback, others should have sync postback. Here a sample to reproduce the...
0
7148
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
7367
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
7517
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...
0
5673
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,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4743
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...
0
1581
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 ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
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...

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.