Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > dataGrid_ItemDataBound - System.InvalidCastException

Reply
Thread Tools

dataGrid_ItemDataBound - System.InvalidCastException

 
 
AZNewsh
Guest
Posts: n/a
 
      11-17-2004
Essentially I am trying to convert a particular column in my datagrid
to an hyperlink on the fly - I have pasted the relevant code and error
below, any advice would be appreciated, I have done several searches
but found nothing that helps.

Code:

Private Sub dataNAV_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dataNAV.ItemDataBound
Try
Select Case e.Item.ItemType
Case ListItemType.AlternatingItem, ListItemType.Item
Dim drv As DataRowView
drv = CType(e.Item.DataItem, DataRowView)
CType(e.Item.Cells(4).Controls(1), Literal).Text =
_
"<a href='" & drv("C_URL").ToString & "'>" & _
drv("C_URL").ToString & "</a>"
End Select
Catch ex As Exception
error_email.fncErrorHandler(ex)
Label1.Text = ex.ToString
End Try
End Sub

Error:

System.InvalidCastException: Specified cast is not valid. at
spac.update.dataNAV_ItemDataBound(Object sender, DataGridItemEventArgs
e) in c:\inetpub\wwwroot\spac\adminspac\maintain\update. aspx.vb:line
113

{line 113 is: drv = CType(e.Item.DataItem, DataRowView)}

Thanks...
 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      11-18-2004
Debug by setting a breakpoint on the line that causes the error. When
it kicks into the debugger, use the Immediate Window to emit the type of
e.Item.DataItem, checking to see if it's a DataRowView or something
else. (Clearly it's not a DataRowView, or you wouldn't be getting the
casting error.)


AZNewsh wrote:
> Essentially I am trying to convert a particular column in my datagrid
> to an hyperlink on the fly - I have pasted the relevant code and error
> below, any advice would be appreciated, I have done several searches
> but found nothing that helps.
>
> Code:
>
> Private Sub dataNAV_ItemDataBound(ByVal sender As Object, ByVal e
> As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> dataNAV.ItemDataBound
> Try
> Select Case e.Item.ItemType
> Case ListItemType.AlternatingItem, ListItemType.Item
> Dim drv As DataRowView
> drv = CType(e.Item.DataItem, DataRowView)
> CType(e.Item.Cells(4).Controls(1), Literal).Text =
> _
> "<a href='" & drv("C_URL").ToString & "'>" & _
> drv("C_URL").ToString & "</a>"
> End Select
> Catch ex As Exception
> error_email.fncErrorHandler(ex)
> Label1.Text = ex.ToString
> End Try
> End Sub
>
> Error:
>
> System.InvalidCastException: Specified cast is not valid. at
> spac.update.dataNAV_ItemDataBound(Object sender, DataGridItemEventArgs
> e) in c:\inetpub\wwwroot\spac\adminspac\maintain\update. aspx.vb:line
> 113
>
> {line 113 is: drv = CType(e.Item.DataItem, DataRowView)}
>
> Thanks...



--

Scott Mitchell
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Create linkbutton in datagrid_ItemDataBound event, how catch click? Teemu Keiski ASP .Net 0 01-02-2006 06:26 PM
DataGrid_ItemDataBound =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 1 09-10-2005 08:00 PM
datagrid_ItemDataBound question =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 2 11-24-2004 01:31 AM



Advertisments