我有一个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") %>'/>
在运行时抛出“指定的强制转换无效错误”。这与
有关SelectedIndex='<%# Eval("subs_template") %>'
表达式,但subs_template保证是一个数字:
<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>
为什么这会一直失败?
我试过了
SelectedIndex='<%# 0 %>'
哪个工作正常!
答案 0 :(得分:1)
您是否尝试过像这样的整数? Convert.ToInt32(Eval("subs_template"))