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. | | | | 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.
>
| | | | 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:
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:
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 -
| | | | 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:
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:
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 -
>
>
| | | | 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:
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:
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 -
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|