Forum Moderators: open

Message Too Old, No Replies

GridView and ImageField

problem with bound data

         

g8tuananh

11:24 am on Mar 6, 2007 (gmt 0)

10+ Year Member



i use GridView and ObjectDataSource
<asp:GridView ID="GridView1" runat="server">
<asp:ImageField DataAlternateTextField="images" DataAlternateTextFormatString="http://localhost:1468/HangDoc/{0}"
DataImageUrlField="images" DataImageUrlFormatString="http://localhost:1468/HangDoc/{0}"
HeaderText="showimage">
</asp:ImageField>
</asp:GridView>

ObjectDataSource has method Datatable Select() and datatable has field images.
proplem is size of field images is 50, but data is lessthan (ex: pic1.jpg)
when it bound to <asp:ImageField is contain blank (ex: pic1.jpg____) so it can't display image on ImageField.
How can i use Trim() method at DataImageUrlFormatString
anyone can help me to solve this problem?
thanks

TheNige

7:59 pm on Mar 6, 2007 (gmt 0)

10+ Year Member



Can you change it in your datasource? Are you use SQL Server? If so, use varchar(50) datatype so you don't have the extra spaces at the end. You can also use LTRIM and RTRIM in your SQL query on the field.

To fix it when you databind to the gridview you may have to override the OnDataBound event to look at the data in the field and then trim it.

[edited by: TheNige at 8:02 pm (utc) on Mar. 6, 2007]

g8tuananh

7:48 am on Mar 7, 2007 (gmt 0)

10+ Year Member



thank you, it work correct!