【问题标题】:ASPxComboBox 'specified cast is not valid' error when data binding数据绑定时 ASPxComboBox 'specified cast is not valid' 错误
【发布时间】:2011-09-26 08:58:33
【问题描述】:

我有一个 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") %>'/>

在运行时会引发“Specified cast is not valid error”。这与

有关
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 %>'

效果很好!

【问题讨论】:

    标签: asp.net data-binding devexpress aspxcombobox


    【解决方案1】:

    你试过把它转换成这样的整数吗? Convert.ToInt32(Eval("subs_template"))

    【讨论】:

    • 有效。我早该想到的!非常感谢您的帮助
    猜你喜欢
    • 2012-09-15
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2020-06-05
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    相关资源
    最近更新 更多