Valley
Valley

Reputation: 71

Error: Specified cast is not valid.

I am getting the following error. Please help me

    Line 90:                 <asp:TemplateField HeaderText="Notes">
Line 91:                     <ItemTemplate>
Line 92:                         <asp:ImageButton ID="btnShowPopup" Text="Notes" Visible='<%#Eval("notesVisible")%>' runat="server" ImageUrl="~/Images/Imgs.jpg"
Line 93:                             OnClick="Popup" />
Line 94:                     </ItemTemplate>

Upvotes: 1

Views: 1196

Answers (3)

SumairIrshad
SumairIrshad

Reputation: 1751

use visible='<%# bool.Parse(Eval("notesVisible").ToString()) %>'

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460308

What type is notesVisible? If it's not a bool but an int:

Visible='<%#((int)Eval("notesVisible")) == 1 ? true : false%>'

Edit: Since you have mentioned that there are nulls:

Visible='<%#Eval("notesVisible") == DBNull.Value ? false : Convert.ToBoolean(Eval("notesVisible"))%>

Upvotes: 2

Sain Pradeep
Sain Pradeep

Reputation: 3125

you need to set visible property with boolean vale "true" or "false"

Eval("notesVisible") is a object not a boolean

Please use it as blow

Visible='<%#(Eval("notesVisible").ToString()=="somthing"?true:false)%>'

I hope it will help you.

Upvotes: 0

Related Questions