locked
BoundField Appends 's' to file Path RRS feed

  • Question

  • User-665118357 posted

    Hi Guys,

    I'm trying to show an image from a database path in an ImageColumn in an asp.net datagrid view. After getting a few null images back. I tried to move the "Image" field to a BoundField to see what path it was coming up with. It seems to keep appending an 's' to the end of the file path. Am I doing something wrong? Here's what I'm working with:

    Thanks In Advance. :)

         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=K:\[DATABASES]\Entry\Entry.accdb"
             ProviderName="System.Data.OleDb" 
             SelectCommand="SELECT [Name], [TimeIn], [Company], [Visiting], [REG], [Image] FROM [Log] WHERE [STATUS] = 'IN'" UpdateCommandType="Text"
             
             ></asp:SqlDataSource>
        <div>
                
             <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="5"  HorizontalAlign="Center">
               <HeaderStyle BackColor="#989898" ForeColor="white" />
                     
                 <Columns>
                   <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-HorizontalAlign="Center" SortExpression="Name" >
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                     </asp:BoundField>
                    <asp:BoundField DataField="TimeIn" HeaderText="TimeIn" SortExpression="TimeIn" />
                    <asp:BoundField DataField="Company" HeaderText="Company"  HeaderStyle-HorizontalAlign="Center" SortExpression="Company" >
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                     </asp:BoundField>
                    <asp:BoundField DataField="Visiting" HeaderText="Visiting"  HeaderStyle-HorizontalAlign="Center" SortExpression="Visiting" >
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                     </asp:BoundField>
                    <asp:BoundField DataField="REG" HeaderText="REG"  HeaderStyle-HorizontalAlign="Center" SortExpression="REG" >
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                     </asp:BoundField>
                    <asp:ButtonField ButtonType="Button" CommandName="Update" Text="Sign Out" />
                     <asp:BoundField DataField="Image" SortExpression="Image" />
                </Columns>
                 
            </asp:GridView>
    Wednesday, November 29, 2017 6:09 PM

Answers

  • User-1716253493 posted

    Simply save filename only or foldername/filename

    To show images under ~/images folder, use this formatstring

                        <asp:ImageField DataImageUrlField="image" DataImageUrlFormatString="~/images/{0}" HeaderText="Image">
                        </asp:ImageField>

    or

                        <asp:TemplateField HeaderText="Image">
                            <ItemTemplate>
                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("image", "~/images/{0}") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 30, 2017 4:32 AM
  • User-335504541 posted

    Hi Kodash,

    I have tested your code, and I don't get any additional character.

    Do you have other code working with this gridview?

    I think you could try to test your code in an empty project to see whether this problem happens again.

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 30, 2017 5:35 AM

All replies

  • User753101303 posted

    Hi,

    Have you tried to look at your database? I see nothing obvious and if this extra letter is found already in the db it would be rather a problem in your upload code.

    Wednesday, November 29, 2017 6:38 PM
  • User-665118357 posted
    Hi,
    Everything in the database looks fine. I even changed the records to a few different paths :/

    Wednesday, November 29, 2017 8:55 PM
  • User-1716253493 posted

    Simply save filename only or foldername/filename

    To show images under ~/images folder, use this formatstring

                        <asp:ImageField DataImageUrlField="image" DataImageUrlFormatString="~/images/{0}" HeaderText="Image">
                        </asp:ImageField>

    or

                        <asp:TemplateField HeaderText="Image">
                            <ItemTemplate>
                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("image", "~/images/{0}") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 30, 2017 4:32 AM
  • User-335504541 posted

    Hi Kodash,

    I have tested your code, and I don't get any additional character.

    Do you have other code working with this gridview?

    I think you could try to test your code in an empty project to see whether this problem happens again.

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 30, 2017 5:35 AM
  • User-665118357 posted

    I think there must be something. I made a new project. and everything works now. (using  oned_gk's  DataImageUrlFormatString="~/images/{0}") which I never would have worked out on me own

    Strangest thing :/

    Thanks for your help Guys!

    Thursday, November 30, 2017 9:16 AM