Connecting Tech Pros Worldwide Forums | Help | Site Map

GridView, dynamic template fields, FindControl problem

beton3000@gmail.com
Guest
 
Posts: n/a
#1: Sep 1 '07
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.


Teemu Keiski
Guest
 
Posts: n/a
#2: Sep 1 '07

re: GridView, dynamic template fields, FindControl problem


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


<beton3000@gmail.comwrote in message
news:1188645008.862770.9400@g4g2000hsf.googlegroup s.com...
Quote:
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.
>

beton3000@gmail.com
Guest
 
Posts: n/a
#3: Sep 1 '07

re: GridView, dynamic template fields, FindControl problem


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:
Quote:
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:1188645008.862770.9400@g4g2000hsf.googlegroup s.com...
>
>
>
Quote:
Hello!
>
Quote:
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:
>
Quote:
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:
>
Quote:
CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;
>
Quote:
cb.DataBinding += new
EventHandler(this.CB_DataBinding);
>
Quote:
container.Controls.Add(cb);
break;
>
Quote:
default:
>
Quote:
break;
}
}
>
Quote:
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.
>
Quote:
I have no more ideas how to solve this problem, please help me.- Ukryj cytowany tekst -
>
- Poka cytowany tekst -

Teemu Keiski
Guest
 
Posts: n/a
#4: Sep 2 '07

re: GridView, dynamic template fields, FindControl problem


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

<beton3000@gmail.comwrote in message
news:1188665015.200518.307800@22g2000hsm.googlegro ups.com...
Quote:
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:
Quote:
>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:1188645008.862770.9400@g4g2000hsf.googlegrou ps.com...
>>
>>
>>
Quote:
Hello!
>>
Quote:
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:
>>
Quote:
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:
>>
Quote:
CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;
>>
Quote:
cb.DataBinding += new
EventHandler(this.CB_DataBinding);
>>
Quote:
container.Controls.Add(cb);
break;
>>
Quote:
default:
>>
Quote:
break;
}
}
>>
Quote:
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.
>>
Quote:
I have no more ideas how to solve this problem, please help me.- Ukryj
cytowany tekst -
>>
>- Poka cytowany tekst -
>
>

beton3000@gmail.com
Guest
 
Posts: n/a
#5: Sep 2 '07

re: GridView, dynamic template fields, FindControl problem


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:
Quote:
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:1188665015.200518.307800@22g2000hsm.googlegro ups.com...
>
>
>
Quote:
Thank you for your answer.
>
Quote:
I have a reload_controls() method which is run in following cases:
>
Quote:
Page_Load / !IsPostBack
GridView_RowEditing
GridView_RowCancelingEdit
>
Quote:
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...
>
Quote:
On 1 Wrz, 15:37, "Teemu Keiski" <jot...@aspalliance.comwrote:
Quote:
Do you instantiate the template in every request? Best way to do it would
be
in OnInit event of the Page.
>
Quote:
Quote:
--
Teemu Keiski
AspInsider, ASP.NET
MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net
>
Quote:
Quote:
<beton3...@gmail.comwrote in message
>
Quote:
Quote:
>news:1188645008.862770.9400@g4g2000hsf.googlegrou ps.com...
>
Quote:
Quote:
Hello!
>
Quote:
Quote:
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:
>
Quote:
Quote:
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.DataRow:
>
Quote:
Quote:
CheckBox cb = new CheckBox();
cb.Enabled = true;
cb.ID = columnName;
>
Quote:
Quote:
cb.DataBinding += new
EventHandler(this.CB_DataBinding);
>
Quote:
Quote:
container.Controls.Add(cb);
break;
>
Quote:
Quote:
default:
>
Quote:
Quote:
break;
}
}
>
Quote:
Quote:
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.
>
Quote:
Quote:
I have no more ideas how to solve this problem, please help me.- Ukryj
cytowany tekst -
>
Quote:
Quote:
- Poka cytowany tekst -- Ukryj cytowany tekst -
>
- Poka cytowany tekst -

Closed Thread


Similar ASP.NET bytes