Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Keeping DataGrid Columns through Postback

Reply
Thread Tools

Keeping DataGrid Columns through Postback

 
 
Allen K
Guest
Posts: n/a
 
      04-06-2004
I have a Datagrid that has programmatically added columns, as well as
columns added through the VS.NET DataGrid Control Editor. Everything is
fine the first time around when the page loads, but when I do a postback,
the columns that I programmatically added disappear. The columns I added
through the Control Editor however are still visible.

Anyone have any idea as to what the problem might be? Does it have
something to do with the columns not persisting in viewstate? How do I fix
this?

Thanks!
Allen
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      04-06-2004
Hi,

you need to add columns on every request, they act like other controls in
that sense that they need to be recreated for each request.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Allen K" <x******@hotmail.com> wrote in message
news:Xns94C2C45CF677Ablahblahcom@198.161.157.145.. .
> I have a Datagrid that has programmatically added columns, as well as
> columns added through the VS.NET DataGrid Control Editor. Everything is
> fine the first time around when the page loads, but when I do a postback,
> the columns that I programmatically added disappear. The columns I added
> through the Control Editor however are still visible.
>
> Anyone have any idea as to what the problem might be? Does it have
> something to do with the columns not persisting in viewstate? How do I fix
> this?
>
> Thanks!
> Allen



 
Reply With Quote
 
 
 
 
Allen K
Guest
Posts: n/a
 
      04-07-2004
I tried re-adding the columns in the Page_Load method on every postback but
that doesn't seem to work.. The only way I can get it to work is if I
rebind the DataGrid each time.. however that doesn't seem like an elegant
solution considering that I have a huge datagrid and the same information
needs to be persisted through 10 or so postbacks.. I don't want to have to
rebind each time..

Help please!

"Teemu Keiski" <(E-Mail Removed)> wrote in news:uEwnH49GEHA.2052
@TK2MSFTNGP11.phx.gbl:

> Hi,
>
> you need to add columns on every request, they act like other controls in
> that sense that they need to be recreated for each request.
>


 
Reply With Quote
 
Guest
Posts: n/a
 
      04-19-2004
I am doing the exact same thing you are requesting. Here
is what you do:
1. You must wire-up a method to the eventhandler of the
grid called ItemDataBound.
this.dgServices.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler
(this.dgServices_ItemDataBound);
2. Then create a method, usually the same name as the
control with the event after the underscore.
private void dgServices_ItemDataBound(object sender,
DataGridItemEventArgs e)
3. Then, depending on what you are displaying (Header,
Item, Footer) you must write those out to the control.
if(e.Item.ItemType == ListItemType.Header)
if(e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
if(e.Item.ItemType == ListItemType.Pager)

That should get you started. Have fun!

Brian
>-----Original Message-----
>I have a Datagrid that has programmatically added

columns, as well as
>columns added through the VS.NET DataGrid Control

Editor. Everything is
>fine the first time around when the page loads, but when

I do a postback,
>the columns that I programmatically added disappear. The

columns I added
>through the Control Editor however are still visible.
>
>Anyone have any idea as to what the problem might be?

Does it have
>something to do with the columns not persisting in

viewstate? How do I fix
>this?
>
>Thanks!
>Allen
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
datagrid hidden field not keeping state after postback Rodusa ASP .Net 2 02-15-2005 03:55 PM
DataGrid Columns lost on Postback???? Allen K ASP .Net 3 04-08-2004 10:26 PM
Binded Datagrid Formatting columns or hiding columns ton ASP .Net Web Controls 2 02-11-2004 04:09 AM
Datagrid Dynamic Columns Postback and SelectedIndexChanged problems George ASP .Net Datagrid Control 1 01-22-2004 04:49 PM
Columns and Inherited Datagrid...Active Schema does not support columns rob thomson ASP .Net Datagrid Control 0 09-04-2003 03:09 PM



Advertisments