473,325 Members | 2,872 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,325 software developers and data experts.

GridView, dynamic template fields, FindControl problem

Hello!

I'm building a GridView using code to add template fields, because
there is a random number of columns in result set from database. I'm
using a class with ITemplate interface for defining columns. I am
using a code which adds a checkbox for each column:

public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:

CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;

cb.DataBinding += new
EventHandler(this.CB_DataBinding);

container.Controls.Add(cb);
break;

default:

break;
}
}

When I display the grid, everything looks fine, but when the page is
postback and GridView_RowUpdating event occurs, I'm unable to find any
checkbox using GridView.Rows[e.RowIndex].FindControl method. I am able
only to find empty TableCells.

I have no more ideas how to solve this problem, please help me.

Sep 1 '07 #1
4 9004
Do you instantiate the template in every request? Best way to do it would be
in OnInit event of the Page.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
<be*******@gmail.comwrote in message
news:11********************@g4g2000hsf.googlegroup s.com...
Hello!

I'm building a GridView using code to add template fields, because
there is a random number of columns in result set from database. I'm
using a class with ITemplate interface for defining columns. I am
using a code which adds a checkbox for each column:

public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:

CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;

cb.DataBinding += new
EventHandler(this.CB_DataBinding);

container.Controls.Add(cb);
break;

default:

break;
}
}

When I display the grid, everything looks fine, but when the page is
postback and GridView_RowUpdating event occurs, I'm unable to find any
checkbox using GridView.Rows[e.RowIndex].FindControl method. I am able
only to find empty TableCells.

I have no more ideas how to solve this problem, please help me.

Sep 1 '07 #2
Thank you for your answer.

I have a reload_controls() method which is run in following cases:

Page_Load / !IsPostBack
GridView_RowEditing
GridView_RowCancelingEdit

reload_controls() consists code which read data from controls on page,
builds gridview (using template fields) and finally calls
GridView.DataBind(). If I try to run reload_controls() from OnInit, I
see an obvious error saying that controls are not instantiated.
Unfortunatelly I need to read from other controls to build gridview...
On 1 Wrz, 15:37, "Teemu Keiski" <jot...@aspalliance.comwrote:
Do you instantiate the template in every request? Best way to do it would be
in OnInit event of the Page.

--
Teemu Keiski
AspInsider, ASP.NET MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net

<beton3...@gmail.comwrote in message

news:11********************@g4g2000hsf.googlegroup s.com...
Hello!
I'm building a GridView using code to add template fields, because
there is a random number of columns in result set from database. I'm
using a class with ITemplate interface for defining columns. I am
using a code which adds a checkbox for each column:
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:
CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;
cb.DataBinding += new
EventHandler(this.CB_DataBinding);
container.Controls.Add(cb);
break;
default:
break;
}
}
When I display the grid, everything looks fine, but when the page is
postback and GridView_RowUpdating event occurs, I'm unable to find any
checkbox using GridView.Rows[e.RowIndex].FindControl method. I am able
only to find empty TableCells.
I have no more ideas how to solve this problem, please help me.- Ukryj cytowany tekst -

- Poka cytowany tekst -

Sep 1 '07 #3
Hi,

see: http://discuss.joelonsoftware.com/de...et.12.350266.2

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

<be*******@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
Thank you for your answer.

I have a reload_controls() method which is run in following cases:

Page_Load / !IsPostBack
GridView_RowEditing
GridView_RowCancelingEdit

reload_controls() consists code which read data from controls on page,
builds gridview (using template fields) and finally calls
GridView.DataBind(). If I try to run reload_controls() from OnInit, I
see an obvious error saying that controls are not instantiated.
Unfortunatelly I need to read from other controls to build gridview...
On 1 Wrz, 15:37, "Teemu Keiski" <jot...@aspalliance.comwrote:
>Do you instantiate the template in every request? Best way to do it would
be
in OnInit event of the Page.

--
Teemu Keiski
AspInsider, ASP.NET
MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net

<beton3...@gmail.comwrote in message

news:11********************@g4g2000hsf.googlegrou ps.com...
Hello!
I'm building a GridView using code to add template fields, because
there is a random number of columns in result set from database. I'm
using a class with ITemplate interface for defining columns. I am
using a code which adds a checkbox for each column:
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:
CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;
cb.DataBinding += new
EventHandler(this.CB_DataBinding);
container.Controls.Add(cb);
break;
default:
break;
}
}
When I display the grid, everything looks fine, but when the page is
postback and GridView_RowUpdating event occurs, I'm unable to find any
checkbox using GridView.Rows[e.RowIndex].FindControl method. I am able
only to find empty TableCells.
I have no more ideas how to solve this problem, please help me.- Ukryj
cytowany tekst -

- Poka cytowany tekst -


Sep 2 '07 #4
Thank you very much Teemu. This solution sounds very reasonable.
Unfortunately my time for this problem passed by and I decided not to
use GridView at all in this case... I will build custom table with
checkboxes.
On 2 Wrz, 09:04, "Teemu Keiski" <jot...@aspalliance.comwrote:
Hi,

see:http://discuss.joelonsoftware.com/de...et.12.350266.2

--
Teemu Keiski
AspInsider, ASP.NET MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net

<beton3...@gmail.comwrote in message

news:11**********************@22g2000hsm.googlegro ups.com...
Thank you for your answer.
I have a reload_controls() method which is run in following cases:
Page_Load / !IsPostBack
GridView_RowEditing
GridView_RowCancelingEdit
reload_controls() consists code which read data from controls on page,
builds gridview (using template fields) and finally calls
GridView.DataBind(). If I try to run reload_controls() from OnInit, I
see an obvious error saying that controls are not instantiated.
Unfortunatelly I need to read from other controls to build gridview...
On 1 Wrz, 15:37, "Teemu Keiski" <jot...@aspalliance.comwrote:
Do you instantiate the template in every request? Best way to do it would
be
in OnInit event of the Page.
--
Teemu Keiski
AspInsider, ASP.NET
MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net
<beton3...@gmail.comwrote in message
>news:11********************@g4g2000hsf.googlegrou ps.com...
Hello!
I'm building a GridView using code to add template fields, because
there is a random number of columns in result set from database. I'm
using a class with ITemplate interface for defining columns. I am
using a code which adds a checkbox for each column:
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:
CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;
cb.DataBinding += new
EventHandler(this.CB_DataBinding);
container.Controls.Add(cb);
break;
default:
break;
}
}
When I display the grid, everything looks fine, but when the page is
postback and GridView_RowUpdating event occurs, I'm unable to find any
checkbox using GridView.Rows[e.RowIndex].FindControl method. I am able
only to find empty TableCells.
I have no more ideas how to solve this problem, please help me.- Ukryj
cytowany tekst -
- Poka cytowany tekst -- Ukryj cytowany tekst -

- Poka cytowany tekst -

Sep 2 '07 #5

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

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
by: Rob Roberts | last post by:
Is there any way to add attributes to GridView ButtonFields? I'm looking for a way to add event handlers to ButtonFields. With regular ASP.NET buttons, I can add event handlers by using the...
0
by: JayD | last post by:
I am using Visual Web Developer (vb.net) and have a gridview in a form. I can update records using standard EDIT/UPDATE buttons. However, there are two fields in every record (called ModifiedBy and...
1
by: Chicagoboy27 | last post by:
I have dynamically bound a field to a gridview using the follwoing code: BoundField nameColumn = new BoundField(); nameColumn.DataField = "territory"; nameColumn.HeaderText = "Terr Num";...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
9
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
6
by: Ahmedhussain | last post by:
Hi there, I m doing work on a gridview and Im getting an error: A potentially dangerous Request.Form value was detected from the client (ctl00$Content$GridView1$ctl03$TextBox1="<span...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.