findcontrol in dynamically created edititemtemplate
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdatagridrepeaterdatalist' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Yannick Smits
Inside the DataGrid's update command I can't seem to find (FindControl) the
dynamically created textboxes inside the edititemtemplate.
This is (simplified) what I do:

void dg_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
TextBox dynamicTbx = new TextBox();
dynamicTbx.ID = "testTbx";
e.Item.Cells[2].Controls.Add(dynamicTbx);
}
}
public void dg_Update(Object sender, DataGridCommandEventArgs e)
{
// both methods don't work ("Object reference not set to an instance of an
object. ")
string test1 = ((TextBox)e.Item.Cells[2].FindControl("testTbx")).Text;
string test2 = ((TextBox)e.Item.FindControl("testTbx")).Text;
}

Am I missing something obvious?
Thanks!
Yannick Smits

Reply to this message...
 
    
Marcie Jones (VIP)
Just curious Yannick, why are you creating the edit
textboxes dynamically? Doesn't it automatically build
textboxes when you go into edit mode?

And to answer, I believe that dynamically added
controls are lost on each postback, so you'd have to
re-add them before it gets to your Update event.

Datagrid Girl

--- Yannick Smits <Click here to reveal e-mail address> wrote:
[Original message clipped]

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

Reply to this message...
 
    
Yannick Smits
[Original message clipped]

I'm adding textboxes dyanamically because I do not know how the datagrid
looks like as I'm building a universal SQL Server table editor. Next I do
not only use textboxes but also dropdownlists, dateselectors etc.

[Original message clipped]

Aaargh, that is a strange behaviour! Should I recreate the controls inside
the update eventhandler to retrieve the values??

> Datagrid Girl

Databound Boy

[Original message clipped]

Reply to this message...
 
    
Nick North
I think you have to go back to the old ASP system of accessing the =
controls through Request.Form. I have a similar system that dynamically =
adds dropdown lists and textboxes, and found this article to be very =
helpful: http://www.tripleasp.net/article.aspx?NavID=3D27.

Nick

-----Original Message-----
From:     Yannick Smits [mailto:Click here to reveal e-mail address]=20
Sent:    13 August 2002 12:26
To:    aspngDataGridRepeaterDatalist
Subject:    [aspngdatagridrepeaterdatalist] Re: findcontrol in dynamically =
created edititemtemplate

[Original message clipped]

I'm adding textboxes dyanamically because I do not know how the datagrid
looks like as I'm building a universal SQL Server table editor. Next I =
do
not only use textboxes but also dropdownlists, dateselectors etc.

[Original message clipped]

Aaargh, that is a strange behaviour! Should I recreate the controls =
inside
the update eventhandler to retrieve the values??

> Datagrid Girl

Databound Boy

[Original message clipped]

| [aspngdatagridrepeaterdatalist] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/aspngdatagridrepeaterdatalist.asp =
=3D JOIN/QUIT

Reply to this message...
 
    
Alex Lowe
You could save yourself some time and use Scott's Table Editor Custom
Control (with source) - http://tripleasp.net/TableEditor.aspx.

Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET

***********************************************************
Translate C# code to VB.NET code at
http://aspalliance.com/aldotnet/examples/translate.aspx
***********************************************************

[Original message clipped]

| = JOIN/QUIT

Reply to this message...
 
    
Yannick Smits
Haha, mine is better :)
- foreign key to dropdownlist support
- date selector
- Fieldvalidators (integers)
- checkbox for bit fields
- vertical editing

--
Yannick Smits

"Alex Lowe" <Click here to reveal e-mail address> wrote in message
news:697066@aspngdatagridrepeaterdatalist...
[Original message clipped]

Reply to this message...
 
    
Yannick Smits
Thanks, Nick. That was exactly what I was looking for.
Yannick Smits

"Nick North" <Click here to reveal e-mail address> wrote in message
news:697063@aspngdatagridrepeaterdatalist...

I think you have to go back to the old ASP system of accessing the controls
through Request.Form. I have a similar system that dynamically adds dropdown
lists and textboxes, and found this article to be very helpful:
http://www.tripleasp.net/article.aspx?NavID=27.

Nick

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: 13 August 2002 12:26
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist] Re: findcontrol in dynamically
created edititemtemplate

[Original message clipped]

I'm adding textboxes dyanamically because I do not know how the datagrid
looks like as I'm building a universal SQL Server table editor. Next I do
not only use textboxes but also dropdownlists, dateselectors etc.

[Original message clipped]

Aaargh, that is a strange behaviour! Should I recreate the controls inside
the update eventhandler to retrieve the values??

> Datagrid Girl

Databound Boy

[Original message clipped]

| [aspngdatagridrepeaterdatalist] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngdatagridrepeaterdatalist.asp =
JOIN/QUIT

Reply to this message...
 
 
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DataGridCommandEventArgs
System.Web.UI.WebControls.DataGridItemEventArgs
System.Web.UI.WebControls.ListItemType
System.Web.UI.WebControls.TextBox
System.Windows.Forms.DataGrid
System.Windows.Forms.TextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com