I need to be able to change the value (set it to an empty string) of a Comment column on a GridView when a user clicks on an Edit button (which is a button column within the gridview). I usually perform these types of operations in the RowDatabound event (which was not dependent on another button click), but after pressing the Edit button, no instance of the column is available.
For instance, when the RowDataBound event fires after getting rows from the database (not pressing Edit), I have the following code run depending upon a certain situation:
<code>
Dim txtComments As TextBox = DirectCast(e.Row.FindControl("txtComments"), TextBox)
txtComments.Enabled =
False
</code>
I am able to get an instance of the comments field. However, after pressing the Edit button and executing the same code above, (note that the RowEditing event fires first, then the RowDataBound event) I am not able to get an instance of the column.
I have tried to set the column to an empty string in the RowEditing event, but it doesn't work. Note the followng code:
<code>
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
TryDim row As GridViewRow
row = GridView1.Rows(e.NewEditIndex)
Dim lblOrderID As Label = CType(row.FindControl("lblOrderID"), Label)
Dim lblEvePhone As Label = CType(row.FindControl("lblEvePhone"), Label)
Dim txtComments As TextBox = CType(row.FindControl("txtComments"), TextBox)
GridView1.EditIndex = e.NewEditIndex
txtPrevComments.Text =
String.Empty
txtPrevComments.Text = txtComments.Text
txtComments.Text =
String.Empty
</code>
So, my question is....
How can I set the Comments field to an empty string after the user presses Edit (which is inside the GridView row for the record)?