Dynamic TextBoxes

  • Thread starter Philip Townsend
  • Start date
P

Philip Townsend

I have a datagrid with update buttons that allow editing of records in a
database table. I would like it if when users click an 'Update' button,
all the generated textboxes are cleared. Here is my code that does not
seem to work (and does not throw exceptions)--what am I doing wrong?

protected void EditRecord(object sender, DataGridCommandEventArgs e)
{
dgItems.EditItemIndex = e.Item.ItemIndex;
dgItems.DataSource = CreateDataSource();
dgItems.DataBind();

foreach(Control c in Page.Controls)
{
if(c is TextBox)
{
((TextBox)c).Text="";
}
}
}
 
G

Guest

Page.Controls may not return the textboxes because your textbox could be a child control of other controls in the page
You have to recursively iterate thru/inside the controls in your page looking or your textboxes

----- Philip Townsend wrote: ----

I have a datagrid with update buttons that allow editing of records in
database table. I would like it if when users click an 'Update' button
all the generated textboxes are cleared. Here is my code that does no
seem to work (and does not throw exceptions)--what am I doing wrong

protected void EditRecord(object sender, DataGridCommandEventArgs e

dgItems.EditItemIndex = e.Item.ItemIndex
dgItems.DataSource = CreateDataSource()
dgItems.DataBind()

foreach(Control c in Page.Controls

if(c is TextBox

((TextBox)c).Text=""






*** Sent via Developersdex http://www.developersdex.com **
Don't just participate in USENET...get rewarded for it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top