[Newbie Problem] BC30311: Value of "TableCell' cannot be convertedto 'Integer'.

  • Thread starter Thread starter DC
  • Start date Start date
D

DC

Compiler Error Message: BC30311: Value of type
'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'.
on line 63. while trying to write updates using a DataGrids Update method.

Source Error:

Line 61:
Line 62: 'Read in the values of the updated row
Line 63: Dim ID as Integer = e.Item.Cells(0)
Line 64: Dim strTitle as String =
CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 65: Dim strForeName as String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text

But If I use CType or CInt to convert the TableCell, I get the error...

BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be
converted to 'Integer'. for the line

Dim ID as Integer = CInt(e.Item.Cells(0))

I think I may have a basic conceptual problem with what is happening
here. How does one get a cell from a DataTable in edit mode into an
integer variable?

Here is the code.

Sub dgStaff_Update(sender As Object, e As DataGridCommandEventArgs)

'Read in the values of the updated row
Dim intID as Integer = e.Item.Cells(0)
Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim strForeName as String = CType(e.Item.Cells(2).Controls(0),
TextBox).Text
Dim strSurName as String = CType(e.Item.Cells(3).Controls(0),
TextBox).Text
Dim strRoomNo as String = CType(e.Item.Cells(4).Controls(0),
TextBox).Text
Dim strPhoneNo as String = CType(e.Item.Cells(5).Controls(0),
TextBox).Text
Dim strEmail as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim strStaff as String = CType(e.Item.Cells(7).Controls(0),
TextBox).Text
Dim strRole as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text


'Construct the SQL statement using Parameters
Dim strSQL as String = _
"UPDATE [user_table] SET [Title] = @Title, " & _
"[ForeName] = @ForeName, [SurName] = @SurName " & _
"[RoomNo] = @RoomNo, [PhoneNo] = @PhoneNo " & _
"(e-mail address removed)
 
What are you trying to get at?

Dim ID as Integer = CInt(e.Item.Cells(0)) cannot work!

Remember, that you are accessing a Cells collection. e.Item.Cells(0) simply
gets you a copy of the TableCell control. You can't turn a cell into an
integer. Think of it like this, a table cell renders into a <td></td>.
That's not exactly the behavior here, but you can't turn a non-integer
object into an integer. Can you explain a bit better what you are attempting
to do with this value?

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage


DC said:
Compiler Error Message: BC30311: Value of type
'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'. on
line 63. while trying to write updates using a DataGrids Update method.

Source Error:

Line 61:
Line 62: 'Read in the values of the updated row
Line 63: Dim ID as Integer = e.Item.Cells(0)
Line 64: Dim strTitle as String = CType(e.Item.Cells(1).Controls(0),
TextBox).Text
Line 65: Dim strForeName as String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text

But If I use CType or CInt to convert the TableCell, I get the error...

BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be
converted to 'Integer'. for the line

Dim ID as Integer = CInt(e.Item.Cells(0))

I think I may have a basic conceptual problem with what is happening here.
How does one get a cell from a DataTable in edit mode into an integer
variable?

Here is the code.

Sub dgStaff_Update(sender As Object, e As DataGridCommandEventArgs)

'Read in the values of the updated row
Dim intID as Integer = e.Item.Cells(0)
Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim strForeName as String = CType(e.Item.Cells(2).Controls(0),
TextBox).Text
Dim strSurName as String = CType(e.Item.Cells(3).Controls(0),
TextBox).Text
Dim strRoomNo as String = CType(e.Item.Cells(4).Controls(0),
TextBox).Text
Dim strPhoneNo as String = CType(e.Item.Cells(5).Controls(0),
TextBox).Text
Dim strEmail as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim strStaff as String = CType(e.Item.Cells(7).Controls(0),
TextBox).Text
Dim strRole as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text


'Construct the SQL statement using Parameters
Dim strSQL as String = _
"UPDATE [user_table] SET [Title] = @Title, " & _
"[ForeName] = @ForeName, [SurName] = @SurName " & _
"[RoomNo] = @RoomNo, [PhoneNo] = @PhoneNo " & _
"(e-mail address removed)
 
Compiler Error Message: BC30311: Value of type
'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'.
on line 63. while trying to write updates using a DataGrids Update method.

Source Error:

Line 61:
Line 62: 'Read in the values of the updated row
Line 63: Dim ID as Integer = e.Item.Cells(0)
Line 64: Dim strTitle as String =
CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 65: Dim strForeName as String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text

But If I use CType or CInt to convert the TableCell, I get the error...

BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be
converted to 'Integer'. for the line

Dim ID as Integer = CInt(e.Item.Cells(0))

I think I may have a basic conceptual problem with what is happening
here. How does one get a cell from a DataTable in edit mode into an
integer variable?
e.Item.Cells(0) should be e.Item.Cells(0).Text

the object returned by e.Item.Cells(0) is a TableCell - a rich object
that can have it's font, colour, style, etc read or changed. What
you're wanting to deal with is the *content* of the cell, which is
returned by the Text property.

Damien
 
e.Item.Cells(0) should be e.Item.Cells(0).Text
the object returned by e.Item.Cells(0) is a TableCell - a rich object
that can have it's font, colour, style, etc read or changed. What
you're wanting to deal with is the *content* of the cell, which is
returned by the Text property.

Damien

Great Damien thanks a lot. I think it will take a while for me to get my
head round the objects in .net :D

Luck,
 
Back
Top