"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, July 23, 2010

Accessing Textbox (any asp.net ) Control on Edit Mode in Grid View

Hi friendz,
If you are working with GridView BoundField Columns and wanted to access the TextBox control on row editing for whatever reasons (which means when you click on the Edit link) then below is an example on how to do it.


Let say for example you need to change the BackColor of the TextBox on edit mode. So at  PreRender event of GridView, you can do something like this:

Code
protected void GridView1_PreRender(object sender, EventArgs e) {
                if (this.GridView1.EditIndex != -1) {
                    TextBox tb = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[1].Controls[0];
                    tb.BackColor = System.Drawing.Color.Blue;
                }
    }

 That's simple! I hope someone find this post useful!
Have a nice day... 'N happy Coding :)

ASP.NET Data Web Controls Kick StartProfessional DevExpress<sup><small>TM</small></sup> ASP.NET ControlsGridview, Style A, 12/bx 


No comments: