Error loading null image from database: Input string was not in a correct format.

2 posts, 0 answers
  1. Adeyeye
    Adeyeye avatar
    1 posts
    Member since:
    Jan 2012

    Posted 25 Jan 2012 Link to this post

    I kept getting error (Input string was not in a correct format.) loading image from database. some of the values are empty(null).
    trying to work around null value, i use dbnull to check for null value and make the pix to be null. it gave me the error above.
    Most of the solutions i get online did not work for me.

    This is my code.
    <div>
    <asp:ScriptManager ID="scmn" runat="server" ></asp:ScriptManager>
    <asp:UpdatePanel ID="upd" runat="server" >
        <ContentTemplate>
        <asp:SqlDataSource id="dsTrucks" runat="server"
        SelectCommand="SELECT DriverID, UPPER(FirstName) + ', ' + Lastname + ' ' + OtherName AS FullName, dateOfBirth, PlaceOfBirth, StateOfOrigin, Telefone AS Phone, HomeAddress, Picture FROM Trip.Driver ORDER BY FirstName, Lastname, OtherName"
                ConnectionString="<%$ ConnectionStrings:defaultcon %>">
            
        </asp:SqlDataSource>

            <telerik:RadListView ID="RadListView1" runat="server"
            ItemPlaceholderID="ListViewContainer" AllowPaging="True"
                DataSourceID="dsTrucks">
            <LayoutTemplate>
                    <asp:PlaceHolder runat="server" id="ListViewContainer" /></LayoutTemplate>
                    <ItemTemplate>
                    <fieldset>
                        <legend><b>Driver No: </b><%#Eval("DriverID")%></legend>
                        <div class="details">
                            <div style="padding: 5px">
                        <table class="templateTable">
                            <tr>
                                <td rowspan="5">
                                    <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Picture") == DBNull.Value ? null : Eval("Picture")%>'
                                    AutoAdjustImageControlSize="True" Width="120px" Height="140px" ToolTip='<%#Eval("DriverID", "Driver {0} picture.") %>'
                                    AlternateText='<%#Eval("DriverID", "Driver {0} picture.}") %>' ResizeMode="Fit" />
                                    <a ID="A4" runat="server" class="thickbox"
                                href='<%# Eval("DriverID", "driver_attachpix.aspx?DriverID={0}&TB_iframe=true&height=320&width=400") %>'
                                title='<%# Eval("DriverID", "Change Picture for {0} ::") %>'>Change Picture</a>
                                </td>
                                <td>
                                    Driver ID.
                                </td>
                                
                                <td class="value">
                                    <asp:Label ID="lblDriverID" runat="server" Text='<%# Eval("DriverID") %>' />
                                </td>
                                <td>
                                    Date of Birth
                                </td>
                                <td class="value">
                                <asp:Label ID="lblDateofbirth" runat="server" Text='<%# Eval("dateofBirth", "{0:d}") %>' />
                                    
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Fullname
                                </td>
                                <td class="value" colspan="3">
                                    <asp:Label ID="lblFullname" runat="server" Text='<%# Eval("Fullname") %>' />
                                   
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Place of Birth
                                </td>
                                <td class="value">
                                    <asp:Label ID="lblPlaceofBirth" runat="server" Text='<%# Eval("PlaceOfBirth") %>' />
                                </td>
                                <td>
                                    State of Origin
                                </td>
                                <td class="value">
                                    <asp:Label ID="lblState" runat="server" Text='<%# Eval("StateOfOrigin") %>' />
                                </td>
                            </tr>
                            <tr >
                                
                                <td >Telephone</td>
                                <td class="value"><asp:Label ID="lbphone" runat="server" Text='<%# Eval("Phone") %>' /></td>
                                <td >Home Address</td>
                                <td class="value"><asp:Label ID="lbAddress" runat="server" Text='<%# Eval("HomeAddress") %>' /></td>
                            </tr>

                            <tr >
                                
                                <td class="value">
                                    <a ID="btnShowPopup" runat="server" class="thickbox"
                                href='<%# Eval("DriverID", "Driver_Details.aspx?DriverID={0}&TB_iframe=true&height=620&width=860") %>'
                                title='<%# Eval("DriverID", "Other details for {0} ::") %>'>Other details</a>
                                </td>
                                <td class="value">
                                    <a ID="A1" runat="server" class="thickbox"
                                href='<%# Eval("DriverID", "Driver_Edit.aspx?DriverID={0}&TB_iframe=true&height=620&width=860") %>'
                                title='<%# Eval("DriverID", "Edit driver {0} details::") %>'>Edit details</a>
                                </td>
                                <td class="value">
                                    <a ID="A2" runat="server" class="thickbox"
                                href='<%# Eval("DriverID", "Truck_RecentTrips.aspx?Driver={0}&TB_iframe=true&height=520&width=700") %>'
                                title='<%# Eval("DriverID", "Recent trips for {0}") %>'>Recent trips</a>
                                </td>
                                <td class="value">
                                <a ID="A3" runat="server" class="thickbox"
                                href='<%# Eval("DriverID", "AssignDriver.aspx?Driver={0}&TB_iframe=true&height=220&width=400") %>'
                                title='<%# Eval("DriverID", "Assign truck for {0}") %>'>Assign Truck</a>
                                </td>
                            </tr>
                           
                            
                        </table>
                    </div>
                        </div>
                    </fieldset>
                    </ItemTemplate>
            </telerik:RadListView>

               
            
        </ContentTemplate>
    </asp:UpdatePanel>
        
    </div>

    Can any1 please help?

  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 30 Jan 2012 Link to this post

    Hello Adeyeye,

    I tried binding a RadBinaryImage in a bound control to a null value and it worked correctly - did not show anything and did not throw and exception. So, please confirm that your conversion works correctly and that there are no mistakes in the syntax.  
    Also, confirm that when you comment out the RadBinaryImage from the RadListView the error goes away, as the wrong string format exception does not sound related to the DbNull value of the binary image's source.

    All the best,
    Tsvetina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top