Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

GridView, dynamic template fields, FindControl problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
beton3000@gmail.com - 01 Sep 2007 12:10 GMT
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 - 01 Sep 2007 14:37 GMT
Do you instantiate the template in every request? Best way to do it would be
in OnInit event of the Page.

Signature

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

> Hello!
>
[quoted text clipped - 31 lines]
>
> I have no more ideas how to solve this problem, please help me.
beton3000@gmail.com - 01 Sep 2007 17:43 GMT
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...

> Do you instantiate the template in every request? Best way to do it would be
> in OnInit event of the Page.
[quoted text clipped - 44 lines]
>
> - Poka  cytowany tekst -
Teemu Keiski - 02 Sep 2007 08:04 GMT
Hi,

see: http://discuss.joelonsoftware.com/default.asp?dotnet.12.350266.2

Signature

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

> Thank you for your answer.
>
[quoted text clipped - 61 lines]
>>
>> - Poka  cytowany tekst -
beton3000@gmail.com - 02 Sep 2007 20:16 GMT
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.

> Hi,
>
[quoted text clipped - 75 lines]
>
> - Poka  cytowany tekst -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.