Dynamic TextBoxes

  • Thread starter Thread starter Philip Townsend
  • Start date 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="";
}
}
}
 
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
 
Back
Top