473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.Columns collection no longer has any knowledge of the
dynamically added TemplateColumn.

I tried setting the CheckBox.EnableViewState = 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 2433
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.Columns collection no longer has any knowledge of the
dynamically added TemplateColumn.

I tried setting the CheckBox.EnableViewState = 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(object savedState)
{
base.LoadViewState (savedState);

CreateTemplateColumns();
}

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
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...
0
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...
3
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...
2
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...
0
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...
0
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...
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...
5
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.