Reputation: 3982
I have a Dev Express ASPxComboBox:
<dx:ASPxComboBox runat="server" ID="DropDownListTemplates"
DataSourceID="SqlDataSourceTemplates" ValueField="template_id" TextField="name"
ValueType="System.Int32" Enabled="false" Width="100%" SelectedIndex='<%#
Eval("subs_template") %>'/>
Which throws a "Specified cast is not valid error" at runtime. It's something to do with the
SelectedIndex='<%# Eval("subs_template") %>'
Expression, however, subs_template is guaranteed to be a number:
<asp:SqlDataSource ID="SqlDataSourceClientDetail" runat="server"
ConnectionString="<%$ code: AutoNat.ConnectionManager.AutoNatConnectionString %>"
SelectCommand="SELECT *, isnull(subs_template_id, 0) subs_template FROM [person] p WHERE [person_id]=@person_id">
<SelectParameters>
<asp:SessionParameter Name="person_id" SessionField="personID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceTemplates" runat="server" ConnectionString="<%$ code: AutoNat.ConnectionManager.AutoNatConnectionString %>"
SelectCommand="SELECT * FROM
(SELECT t.template_id, name FROM subs_template t UNION SELECT 0, 'Custom...') s
ORDER BY template_id">
</asp:SqlDataSource>
Why does this keep failing?
I have tried
SelectedIndex='<%# 0 %>'
Which works fine!
Upvotes: 1
Views: 1121
Reputation: 6802
Have you tried casting it o an integer like this? Convert.ToInt32(Eval("subs_template"))
Upvotes: 1