473,471 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create 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 2407
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
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
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
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
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
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
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
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
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
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: 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
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
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
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
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
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
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.