473,659 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Maintaining state with a dynamically created TemplateColumn

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 TemplateColumn dynamically. I persist a DataSet
in my Session object and I bind the CheckBox to the DataSet. So far so good.
The CheckBoxes show up and the user interacts with them (checks a few,
unchecks a few).

The problem is that during a postback event, I want to update the DataSet
with the results of what the user did to those CheckBoxes. Problem is, that
during postback (eg, when a Button is clicked), the DataGrid.Items collection
and DataGrid.Column s collection no longer has any knowledge of the
dynamically added TemplateColumn.

I tried setting the CheckBox.Enable ViewState = true when I create the
TemplateColumn, but I can't figure out how to get at the dynamically added
CheckBox Controls during postback. Anyone know how to do this?

I have no trouble if I declaratively add the CheckBox TemplateColumns . If I
do that, I can get exactly what I want during postback. But no go when I
create the TemplateColumns dynamically.

Thanks,
Pete
Apr 5 '06 #1
2 2447
You have to create dynamically controls upon each postback during the
page.init event handling.

I have a sample code in asp.net 1.1
http://www.societopia.net/Samples/Da...Delegates.aspx

and another in asp.net 2.0
http://www.webswapp.com/codesamples/...e/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Pete Moss" wrote:
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 TemplateColumn dynamically. I persist a DataSet
in my Session object and I bind the CheckBox to the DataSet. So far so good.
The CheckBoxes show up and the user interacts with them (checks a few,
unchecks a few).

The problem is that during a postback event, I want to update the DataSet
with the results of what the user did to those CheckBoxes. Problem is, that
during postback (eg, when a Button is clicked), the DataGrid.Items collection
and DataGrid.Column s collection no longer has any knowledge of the
dynamically added TemplateColumn.

I tried setting the CheckBox.Enable ViewState = true when I create the
TemplateColumn, but I can't figure out how to get at the dynamically added
CheckBox Controls during postback. Anyone know how to do this?

I have no trouble if I declaratively add the CheckBox TemplateColumns . If I
do that, I can get exactly what I want during postback. But no go when I
create the TemplateColumns dynamically.

Thanks,
Pete

Apr 5 '06 #2
Phillip,

Thanks for the reply and the sample,but appears that your sample is doing
something different and is doing a postback on each CheckBox click. That is
what I am trying to avoid.

I believe I found a solution, however. The trick seemed to be in re-creating
the TemplateColumns during the LoadViewState() override on the page. It
simply looks like this:

protected override void LoadViewState(o bject savedState)
{
base.LoadViewSt ate (savedState);

CreateTemplateC olumns();
}

Once that is done, in a postback event such as a button click, the state of
all DataGrid columns is available to me.

The only annoying thing from my POV is that I have to make sure I update the
DataSet with the current CheckBox states in the TemplateColumns . Otherwise,
I lose the state of the CheckBox when the DataGrid gets updated.

Pete

"Phillip Williams" wrote:
You have to create dynamically controls upon each postback during the
page.init event handling.

I have a sample code in asp.net 1.1
http://www.societopia.net/Samples/Da...Delegates.aspx

and another in asp.net 2.0
http://www.webswapp.com/codesamples/...e/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Apr 8 '06 #3

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

Similar topics

0
2467
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically added row it also removes the row at the end along with the added row. Plz tell me if, I am missing any thing. Code </asp:datagrid>
0
1765
by: Earl Teigrob | last post by:
I am building a custom control that I want to server as a container for child controls that can be dynamically added to this control. I can persist the child controls that are added to my custom control but can to get them to retain view state. Below is a striped down version of my control. It exposes one property of type System.Web.UI.Control that the containing page my set with a dynamically created control My custom control will then...
3
2778
by: jclark0731 | last post by:
I am trying to redirect to the same page after a post-back is fired to ensure that the post-back never makes it into history (avoids the post-back/refresh problem). While doing this, I wish to maintain the view state of the page (page contains dynamic controls as well). Has anybody done this before? I assume that I need to store the viewstate info in session (as the 64-bit encoded string or as the statebag? using sql server session...
2
4130
by: louise raisbeck | last post by:
Hi there, I cannot write a datagrid on the aspx because i do not know the names of the column headings until i run a query. So i have to do it programatically from the datasource. I have managed to add a couple of boundcolumns based on my datasource easy peasy but can't find any help anywhere to show me how to dynamically set up the itemtemplate within a templatecolumn (and add say a checkbox to it). So what goes after this? I know the...
0
1339
by: news.zen.co.uk | last post by:
Hi Guys, Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the Parent (this refelect GUI'wise a Parent Child related data). I also add Handlers to the sub datagrid using AddHandler to handle the EditCommandColumn as well as ItemDataBound. Parent Datagrid...
0
1999
by: Silver Oak | last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was created dynamically using iTemplate. I would like to have multi-row editing capability on the DataGrid. I'm trying to follow the example in MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp Section "Editing Multiple Rows at once". I would like to follow the second solution...
5
4709
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 handler to deal with the Command event, but for some reason I can get this to work in a C# project but not in a newly created VB.NET one. The relevant VB.NET is as follows:
5
2297
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns like so: Dim column as TemplateColumn = new TemplateColumn() column.HeaderText = "Template Column" column.ItemStyle.Width = Unit.Pixel(width) column.HeaderStyle.Width = Unit.Pixel(width)
10
5743
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the images) of the gridview come from a single table/datasource. Here is my situation. In my web application, I need to display customer bills info in a gridview. Customer names and contact info are from the Customer table.
0
8427
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
8851
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
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
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
5649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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
1737
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.