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