This is a migrated thread and some comments may be shown as answers.

cast is not valid on a three toggle state rad button inside a grid

6 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Georges
Top achievements
Rank 1
Georges asked on 08 Sep 2016, 01:11 PM

  <telerik:GridTemplateColumn UniqueName="ORACLE_VERIFIED" HeaderText="Oracle">
                        <ItemTemplate>
                            <telerik:RadButton RenderMode="Lightweight" Checked='<%#Bind("ORACLE_VERIFIED")%>' ID="btnToggleOracle" runat="server" ToggleType="CustomToggle" ButtonType="ToggleButton"
                                AutoPostBack="false">
                                <ToggleStates>
                                    <telerik:RadButtonToggleState Text="Not Verified" Value="0" PrimaryIconCssClass="rbToggleCheckbox" Width ="100px"/>
                                    <telerik:RadButtonToggleState Text="N/A" Value="-1" PrimaryIconCssClass="rbToggleCheckboxFilled" Width ="100px"/>
                                    <telerik:RadButtonToggleState Text="Verified" Value="1" PrimaryIconCssClass="rbToggleCheckboxChecked" Width ="100px"/>
                                </ToggleStates>
                            </telerik:RadButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

 

i am trying to bind a three state toggle button and getting cast not valid. the values are 0,1,-1 if not available. this is oracle and the fields are defines as int in c# . anyone ran into this issue before? thanks

6 Answers, 1 is accepted

Sort by
0
Georges
Top achievements
Rank 1
answered on 08 Sep 2016, 01:23 PM

Checked='<%# (DataBinder.Eval(Container.DataItem,"ORACLE_VERIFIED").ToString()=="-1" ?"N/A":Eval("ORACLE_VERIFIED")) %>'

 

i changed it to this and still getting an error, cast error

0
Georges
Top achievements
Rank 1
answered on 08 Sep 2016, 02:26 PM

Checked='<%# (DataBinder.Eval(Container.DataItem,"ORACLE_VERIFIED").ToString()=="-1" || DataBinder.Eval(Container.DataItem,"ORACLE_VERIFIED") is DBNull ?"N/A":Eval("ORACLE_VERIFIED")) %>'

1) checked gives me the cast error

2) values does not and it does not bind

3) Dbvalue does not but it does not bind either..

not sure what the issues is with cast. could be the last EVAL that needs to be casted to boolean?

0
Maria Ilieva
Telerik team
answered on 13 Sep 2016, 12:05 PM
Hello,

You get this due to the fact that Value is null and Bind() expression will try to assign this to Checked property. You need to have default value (1/0/-1) for Value

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Georges
Top achievements
Rank 1
answered on 13 Sep 2016, 12:53 PM
i get you but no one is giving me example on how to write the syntax, i keep getting errors on different syntax. can you show me an example using my code above.
0
Georges
Top achievements
Rank 1
answered on 13 Sep 2016, 05:45 PM
the actual value is coming back as -1. there is not null but i keep getting cast value error. it does not know how to interpret -1 i guess
0
Maria Ilieva
Telerik team
answered on 16 Sep 2016, 03:08 PM
Hi,

Try setting the values as Text instead of using the Value property and see how it goes.

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Georges
Top achievements
Rank 1
Answers by
Georges
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or