Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid - template column problem

Status
Not open for further replies.

rushdib

Programmer
Jun 12, 2001
203
US
Hi,
I have a problem retreiving values from a template column in a data grid. My code is this

Dim newName As String
Dim box As TextBox

box = e.Item.Cells(1).FindControl("FirstName")
newName = box.Text.ToString

I am getting the follwoing error

Object reference not set to an instance of an object.

Can someone please help me?

Rushdi
 
Should

Code:
Dim box As TextBox

...be...

Code:
Dim box As New TextBox
[code/]

...little uncertain on vb.net as I usually use c#.

Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
Hi,
I tried that. Still the same error.

Rushdi
 
If Not (e.Item.FindControl("FirstName") Is Nothing) Then
Dim FNCol As TableCell = e.Item.Cells(1)
Dim FNColText As String = FNCol.Text
End If

 
Hi,
I found the problem. I haven't named the control "FirstName". It was called "TextBox2".

Rushdi
 
Hi,
Now I have a different problem. The values I am getting by using the following code

dim tbox as new textbox
dim firstName as string

tbox = CType(e.Item.Cells(0).FindControl("FirstName"), TextBox)
firstName = tbox.Text

is the table value. It doesn't bring the change.

Thanks,

Rushdi Basir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top