Link to home
Start Free TrialLog in
Avatar of caibeier
caibeier

asked on

Find Controls in <EditItemTemplate> in GridView web control, ASP.NET 2.0

Hi experts,

I'm have GridView control in my ASP.NET page. Within  <EditItemTemplate> in one of the GridView's columns, there is a Textbox. I'm just wondering, is it possible / how to get a reference of the textbox control so I can do something with it (i.e. When user enter editing mode, set the width of the textbox base on the length of text string)

 I tried the following, but it gives me NullReference exception

Private Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        Dim mytxt As TextBox = Me.GridView1.Rows(e.NewEditIndex).FindControl("txtLastName")
        mytxt.Columns = GridView1.Rows(e.NewEditIndex).Cells(3).Controls.Item(1)      ' This is the text supposed to be  in the textbox
End Sub
ASKER CERTIFIED SOLUTION
Avatar of sandip132
sandip132
Flag of Japan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of caibeier
caibeier

ASKER

Thanks for the info sandip132, I found out that the reason I got NULL Reference is because I disabled the viewstate of the gridview control