helper function gives case error when called during datagrid binding

Discussion in 'ASP .Net' started by bhavin30, Jan 12, 2006.

  1. bhavin30

    bhavin30 Guest

    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

    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
    <ItemStyle Font-Size="11px" Font-Names="Verdana"
    <IMG src="images/detail_lineitems_invoice_no.gif" width="67"
    <asp:HyperLink Font-Size="11px" ForeColor="Blue" Font-Underline=True
    Font-Name="Verdana" Target="Invoice" Runat="server" NavigateUrl='<%#
    <%# DataBinder.Eval(Container.DataItem, "invoice_no") %>

    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

    If sAppFlag = "APW" Then
    sPath = ""
    ElseIf sAppFlag = "JE" Then
    sPath = ""
    sPath = ""
    End If

    Return sPath

    Catch ex As Exception
    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!!
    bhavin30, Jan 12, 2006
    1. Advertisements

  2. 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?
    dim sAppFlag as string = cstr(appFlag)
    'rest of your code
    end if
    end function

    Karl Seguin [MVP], Jan 12, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.