473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Added TemplateColumn is not showing in DataGrid after PostBack

Hello,

Hope somebody can help me with this cause I'm a ASP.NET beginner. I've
created A DataGrid, and I added few BoundedColumns, and in my
Page_Load section I added few TemplateColumns through the
myGrid.Columns.Add(myTemplateColumn). After that I bind the datasource
to the datagrid in the Page_Load only if it is not a postback.
Initially it works fine, but on PostBack (whatever I do on the
webform) my TemplateColumns dissapear :( Only the BoundedColumns stay.

BTW. the code myGrid.Columns.Add(myTemplateColumn) is not in the If
Not IsPostBack section, so it executes on each postback.

Why doesn't it work? I thought you should only do the bind on the
initial Page_Load and not on each postback, cause to me it seems like
a lot of processing (i.e. database connections etc...)... Should it
not be bound only once like my BoundedColumns which show fine on each
postback?
Nov 18 '05 #1
2 1445
I presume that the AutoGenerateColumns property is set to false. If
so, then to the best of my knowledge - the responsibility for
recreating the grid (including postback) - is yours. ASP.NET is
basically non-persistant - it _does_ use the ViewState to restore
several items, but the DataGrid's columns will not be restored, if you
dynamically create them. The technique to do this is either to
recreate everything every time, or to override the LoadViewState
method.

Please follow the instructions on this link:
http://msdn.microsoft.com/library/en...mnsdynamically

Take care that you read the entire section labeled "Adding Columns
Dynamically" - its very easy to miss the LoadViewState section there -
I know I did at first !

Elad.
Nov 18 '05 #2
Hi Jade,

Please ignore my previous post - I believe I misunderstood your
problem.

I think this thread may help solve your problem:
http://groups.google.com/groups?hl=e...TF-8%26hl%3Den

Elad.
Nov 18 '05 #3

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

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
4
by: RN | last post by:
In certain situations, I add a datagrid and a button beneath it. All programmatically added in the "code behind". I add them to a cell with cell.add(datagrid) and cell.add(button). Take the...
2
by: Jim Bancroft | last post by:
Hi everyone, I have a couple of TemplateColumns in my DataGrid that I need to hide from view....yet still have their contents available in the code-behind file. My HTML code looks like this at...
3
by: ad | last post by:
I added column to a DataTable, I want the column to be display in the first place of a dataGrid. The Column in dataGird is auto-generate. How can I do that?
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
3
by: rn5a | last post by:
A DataGrid has the following TemplateColumn: <asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid" AllowSorting="true"....> <Column> <asp:TemplateColumn HeaderImageUrl="Images\Up.gif"...
5
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event...
2
by: =?Utf-8?B?RXVnZW5l?= | last post by:
Hi, I use a datagrid with asp:templatecolumn, and handles the datagrid's ItemDataBound event, whereby I assign a value to this asp:templatecolumn text. e.Item.Cells.Text = e.Item.Cells.Text +...
0
by: Glenn Rosenthal | last post by:
I have a Web page with a datagrid for display search results. The first column contains a check box and a hidden field, and are defined with the datagrid. <asp:DataGrid...
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
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
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...
1
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...
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
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 ...

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.