Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
As my question indicate, I need to show footer in empty gridview but when I put a checkbox and use imageurl with cast to get imageurl from code behind, it raise error, may anyone help me?
Here is my code:
<asp:TemplateField FooterStyle-CssClass="Clm100" HeaderStyle-CssClass="Clm100" HeaderText="<%$ Resources:Pages, CanPrint %>" SortExpression="CanPrint">
<itemtemplate>
<asp:Image ImageUrl=<%# GetCheckMark((bool)Eval("CanPrint")) %>  ID="ImgCanPrint" runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:CheckBox ID="EdtCanPrint" runat="Server" Checked='<%# Eval("CanPrint") %>'>
</edititemtemplate>
<footertemplate>
<asp:CheckBox CssClass="Clm100" ID="FooterCanPrint" runat="server" />
</footertemplate>


and cast
protected string GetCheckMark(bool checkd)
{ 
    return checkd ? "../../../../../ServerFile/Icons/Editor/True.png" : "../../../../../ServerFile/Icons/Editor/False.png";
}



and cast
Posted
Updated 20-Apr-12 20:26pm
v2
Comments
Sandeep Mewara 21-Apr-12 3:16am    
Not clear on what you want. Please re-phrase and also add the error that you are getting.
A.Ebrahimi 21-Apr-12 3:41am    
This is error:
Exception Details: System.InvalidCastException: Specified cast is not valid.
More information: since the field in grid in null, the cast face error and since the eval("CanPrint") is boolean I don't know how to avoid it.
It seems that I must check null value before using cast, but I don't know how?
Thanks
A.Ebrahimi 21-Apr-12 3:55am    
Hi again:
As I check, only whet table is empty it raise error with cast. I changed my cast but I have problem:
Convert.ToBoolean(Eval("CanSee"))?"~/ServerFile/Icons/Editor/True.png":"~/ServerFile/Icons/Editor/False.png"
Error:
Object cannot be cast from DBNull to other types.

1 solution

As I have found the main cause of this error is when table is empty then there is no value to pass to eval and it raise error. So change my question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900