forum

Home / DeveloperSection / Forums / Clear Textboxes in Gridview Cells

Clear Textboxes in Gridview Cells

Samuel Fernandes 1628 14-Nov-2013

The gridview has multiple rows and columns and each cell has a textbox, validator controls. The columns are generated dynamically, and I would like to clear all the textboxes.

This is not working. Where am I going wrong

protected void btnClear_Click(object sender, EventArgs e)
{
 if(gvMain.Rows.Count > 0)
  {
    foreach(GridViewRow gvr in gvMain.Rows)
     {
       foreach(TableCell tc in gvr.Cells)
        {
           if(tc.HasControls())
            {
              for(int i=0;i<tc.Controls.Count;i++)
               {
                 if(tc.Controls[i] is TextBox)
                   {
                     TextBox tb = (TextBox)tc.Controls[i];
                      tb.Text= "";
                   }
               }
            }
        }
     }
  }
}

c# c# 
Updated on 14-Nov-2013

Can you answer this question?


Answer

1 Answers

Liked By