By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Displaying Image from DB inside a Gridview

P: 2
Hi folks,

Been struggling with this little puzzle.

I am reading the MemberInfo table for the ClubStarterKit, the table includes the Avatar for the User.

I would like to display the Avatar as an image in a databound element, in this case I am resorting to Gridview although I would prefer datalist or something simpler.


<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ connectionStrings:ClubSiteDB %>"

SelectCommand="SELECT aspnet_Users.UserName, aspnet_Users.UserId, Attendance.numofguest, MemberInfo.avatar FROM Attendance INNER JOIN aspnet_Users ON Attendance.member = aspnet_Users.UserId INNER JOIN MemberInfo ON Attendance.member = MemberInfo.memberid WHERE (Attendance.eventid = @id)">
<asp:QueryStringParameter DefaultValue="1" Name="id" QueryStringField="EventId" Type="Int32" />

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataSourceID="SqlDataSource2" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataMember="DefaultView">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="numofguest" HeaderText="Number of Guests" SortExpression="numofguest" />
<asp:BoundField DataField="avatar" HeaderText="avatar" SortExpression="avatar" >

<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />


When I configure the SqlDatasource and test the query it actualy shows the Image in the TestQuery Results window. But when I run my page the Gridview populates with the other columns but in the AVATAR it shows byte[]

What should I do to get this working?
Mar 19 '06 #1
Share this Question
Share on Google+
1 Reply

P: 1
Hi all,

I am also trying to display an image from DB to gridview. Has anyone done this and can advise on how to do it?

Currently, I have one table which has ID, name, photo attributes for each record. The gridview is currently displaying ID and name only :( The photo is stored as an image data type in SQL server 2005 express.

Any help would be greatly appreciated

Oct 16 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.