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
|
|
| |
| |
| 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
|
|
| |
|
| |
| 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]
|
|
| |
|
| |
| 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
|
|
| |
|
| | |
| |
| 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]
|
|
| |
|
| |
| 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
|
|
| |
|
|
|
|
|