473,770 Members | 4,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TemplateField in 2.0 // Disappears on Postback when TemplateField is added thru code


I am programmaticall y adding
BoundField's and
TemplateField's
to a GridView.

I have it working fine.

BoundField bf = new BoundField();
bf.DataField = "EmpID";
bf.HeaderText = "The Employee ID";
bf.SortExpressi on = "EmpID";
mygridview.Colu mns.Add(bf);
I know the TemplateFields are not as simply created, but I do have them
working.

TemplateField tf = new TemplateField() ;
tf.ItemTemplate = new // My Custom Implementation
tf.HeaderTempla te = new //My Custom Implementation

mygridview.Colu mns.Add(tf);


The issue arises when I do postbacks..name ly the sorting or paging.

When I page or sort the gridview.. the PostBack occurs.

All of the bound field's I've added (programaticall y) are still there.

All the TemplateField's I add programatically disappear.

I've found a few "I have this issue" posts thru googling. But no answers.

Anybody have any ideas?

I've tried to find some property to enable viewstate for the TemplateField,
but its not natively there.

...
Jun 21 '06 #1
1 2290

I haven't gotten a response, so I'll repost:

I'm working up a simple example also:


"sloan" <sl***@ipass.ne t> wrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .

I am programmaticall y adding
BoundField's and
TemplateField's
to a GridView.

I have it working fine.

BoundField bf = new BoundField();
bf.DataField = "EmpID";
bf.HeaderText = "The Employee ID";
bf.SortExpressi on = "EmpID";
mygridview.Colu mns.Add(bf);
I know the TemplateFields are not as simply created, but I do have them
working.

TemplateField tf = new TemplateField() ;
tf.ItemTemplate = new // My Custom Implementation
tf.HeaderTempla te = new //My Custom Implementation

mygridview.Colu mns.Add(tf);


The issue arises when I do postbacks..name ly the sorting or paging.

When I page or sort the gridview.. the PostBack occurs.

All of the bound field's I've added (programaticall y) are still there.

All the TemplateField's I add programatically disappear.

I've found a few "I have this issue" posts thru googling. But no answers.

Anybody have any ideas?

I've tried to find some property to enable viewstate for the TemplateField, but its not natively there.

..

Jun 26 '06 #2

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

Similar topics

4
10991
by: Chris Lane | last post by:
Hi, I have an HTML RESET button and Web Control Button that posts back to the server. Problem is the reset button doesn't work after the postback occurs. Any ideas or suggestions as to why this happens or how I can work around this? Thanks
1
5378
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My question is when the button is clicked and a postback is performed, the controls that were in the placeholder no longer appears on the screen! Am I doing something wrong here? Why are the controls back on the screen eventhough they have enable view...
10
4516
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back (basically have the data binding done in the If NOT IsPostBack Then statement). How come? How does this information get preserved? Which raises another question. Becuase I want to get away from the spaghetti code approach, I would like to create...
1
2742
by: Ryu | last post by:
I am having a problem whereby the controls (along with its values) disappear after I click a button. The controls that I have added is a textbox in a Table. Both of these displayed correctly. Any suggestions will be helpful. Thanks
0
956
by: sunny076 | last post by:
Hi, I am having problem with a derived class from GridView in which I added an empty image in the itemTemplate. Basically what I am trying to do is adding an image column with an arrow instead of a select button. It built fine, but when I modified any of the attributes in teh designer mode, it kept adding another column of the same one. I think the problem is because I added the column in teh class constructor but I
1
21472
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. Unfortunate Outcome: Each checkbox returns false for its attribute:checked whether the user has placed a...
2
10459
by: =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= | last post by:
I am building a GridView dynamically adding templatFields according to a Microsoft article. I had to create a class with the ITemplate interface and a method called InstantiateIn. Everything works fine except that I am unable to sort such a templatefield. AllowSorting is true: <asp:GridView ID="gvwPend" runat="server" AllowSorting="True" AutoGenerateColumns="False" ... OnSorting="gvwPend_Sorting">
1
1830
by: Rafia Tapia | last post by:
Hi I have a gridview control that is showing 6 column. The first column is a buttonfield, then there are three boundfield and two template field control. I am creating all these column in the page load event and initializing the itemtemplate of the template field in rowcreated event. The problem is that my templatefield shows a textbox and the value of the textbox in not retain between postback. Can anyone please help me. Thanks
0
1869
by: rcon | last post by:
I'm creating a user control to prompt for crystal reports parameters. The individual controls work fine, and the over all control works fine too. However, I'm not really that experienced in the use of dynamic controls and am having some issues with getting the accordion to work properly. What happens when one of my user controls fires a postback is that the accordion gets set back to the first pane. I suspect that this is happening...
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7431
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5326
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
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 we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.