开发者

ASPxComboBox 'specified cast is not valid' error when data binding

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 do开发者_如何学运维es this keep failing?

I have tried

SelectedIndex='<%# 0 %>'

Which works fine!


Have you tried casting it o an integer like this? Convert.ToInt32(Eval("subs_template"))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜