473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

helper function gives case error when called during datagrid binding

Hi Guys,
I have a quick question. I think code will explain it the best.
This is what I am doing for one of the columns during databinding on my
grid:

<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Font-Size="11px" Font-Names="Verdana"
HorizontalAlign="Center"></ItemStyle>
<HeaderTemplate>
<IMG src="images/detail_lineitems_invoice_no.gif" width="67"
height="18">
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink Font-Size="11px" ForeColor="Blue" Font-Underline=True
Font-Name="Verdana" Target="Invoice" Runat="server" NavigateUrl='<%#
CheckAppFlagDuringBinding(Container.DataItem("app_ flag"),
Container.DataItem("invoice_id"))%>'>
<%# DataBinder.Eval(Container.DataItem, "invoice_no") %>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
I basically check the flag in CheckAppFlagDuringBinding function, and
return a string value.
Here's the function:

Public Function CheckAppFlagDuringBinding(ByVal sAppFlag As String,
ByVal gInvoiceID As Guid) As String
Dim sPath As String

Try
If sAppFlag = "APW" Then
sPath = "http://nytimes.com"
ElseIf sAppFlag = "JE" Then
sPath = "http://cnet.com"
Else
sPath = "http://boston.com"
End If

Return sPath

Catch ex As Exception
HandleError(ex)
End Try

End Function

It is a very simple function. But when i run this code i get a cast
error: Cast from type 'DBNull' to type string. When i debug the code,
i can see that a string is passed from the function fine (and
correctly), but doesn't seem to 'stick' to the NavigationUrl property
of the column. The function gets called only one time (maybe because
there is only row in the dataset)

Do you know why this might be happening? Any help is really
appreciated. Thanks!!
bhavin


Jan 12 '06 #1
1 1210
It seems like one of your values is null.

you need to change ur method slightly:

public function blah (appflag as object, gInvoiceID as Guid) as string
if appflag is nothing orelse appflag = DBNull.Value then
'what to do if it's a null?
else
dim sAppFlag as string = cstr(appFlag)
'rest of your code
end if
end function

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
<bh******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi Guys,
I have a quick question. I think code will explain it the best.
This is what I am doing for one of the columns during databinding on my
grid:

<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Font-Size="11px" Font-Names="Verdana"
HorizontalAlign="Center"></ItemStyle>
<HeaderTemplate>
<IMG src="images/detail_lineitems_invoice_no.gif" width="67"
height="18">
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink Font-Size="11px" ForeColor="Blue" Font-Underline=True
Font-Name="Verdana" Target="Invoice" Runat="server" NavigateUrl='<%#
CheckAppFlagDuringBinding(Container.DataItem("app_ flag"),
Container.DataItem("invoice_id"))%>'>
<%# DataBinder.Eval(Container.DataItem, "invoice_no") %>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
I basically check the flag in CheckAppFlagDuringBinding function, and
return a string value.
Here's the function:

Public Function CheckAppFlagDuringBinding(ByVal sAppFlag As String,
ByVal gInvoiceID As Guid) As String
Dim sPath As String

Try
If sAppFlag = "APW" Then
sPath = "http://nytimes.com"
ElseIf sAppFlag = "JE" Then
sPath = "http://cnet.com"
Else
sPath = "http://boston.com"
End If

Return sPath

Catch ex As Exception
HandleError(ex)
End Try

End Function

It is a very simple function. But when i run this code i get a cast
error: Cast from type 'DBNull' to type string. When i debug the code,
i can see that a string is passed from the function fine (and
correctly), but doesn't seem to 'stick' to the NavigationUrl property
of the column. The function gets called only one time (maybe because
there is only row in the dataset)

Do you know why this might be happening? Any help is really
appreciated. Thanks!!
bhavin

Jan 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: tshad | last post by:
Is there a way to call a function from a boundcolumn tag? I have some icons that I set as visible or not depending on values set in my table. I have a Datagrid that I am binding to and after...
20
by: alexandre.braganti | last post by:
Hello, First sorry for my poor English, I am French ;-) I've got a comprehension problem of what happend in one of the project i'm working on. Basically I've got a class gs_object than has got...
16
by: mdh | last post by:
May I ask the group the following: (Again, alas , from K&R) This is part of a function: while ( ( array1 = array2 ) != '\0' ); /* etc etc */ Is this the order that this is evaluated? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.