Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 GridView - how to display pictures in a coumn?

Author  Topic 

Richy1
Starting Member

27 Posts

Posted - 2007-05-22 : 09:03:44
Hi all, this is very simple - I have columns linked to a database, no problems. But I want one of the coumns to have pictures in it - how do i go around doing this please? I have to place some type of code, but im not sure how. Any help? thanks.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-22 : 09:05:25
Where are these pictures located?

All you need to do is use a templated column and output an <IMG> tag or an <asp:Image> control.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Richy1
Starting Member

27 Posts

Posted - 2007-05-22 : 10:02:32
ATM, the pics are just placed in a folder - the column is blank as i dont know how to display them yet. Ive tried - <img src="images/1.jpg"> but it just comes up with the syntex in IE.

Im also using Visual web Developer, this is the line of code for the column so far -
<asp:BoundField DataField="Assembly Figure" HeaderText="Assembly Figure" SortExpression="Assembly Figure" />
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-22 : 11:09:37
Are you using a templated column ? We need to see some code, it's pretty hard to guess what's going on.



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Richy1
Starting Member

27 Posts

Posted - 2007-05-22 : 11:18:45
Its a proper database table in SQL server. Once thats done, i then create a DataSet; and then follow the instructions. I then have the GelNano.xsd in the App_Code. Then, in my Dafualt page i then bring down the GridView. The code is here -

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="WhiteSmoke" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" DataSourceID="ObjectDataSource1" Font-Size="X-Small" GridLines="None">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="Model No" HeaderText="Model No" SortExpression="Model No" />
<asp:BoundField DataField="Alternative Battery Ref " HeaderText="Alternative Battery Ref "
SortExpression="Alternative Battery Ref " />
<asp:BoundField DataField="Voltage (V)" HeaderText="Voltage (V)" SortExpression="Voltage (V)" />
<asp:BoundField DataField="Capactiy 10HR(Ah)" HeaderText="Capactiy 10HR(Ah)" SortExpression="Capactiy 10HR(Ah)" />
<asp:BoundField DataField="L" HeaderText="L" SortExpression="L" />
<asp:BoundField DataField="W" HeaderText="W" SortExpression="W" />
<asp:BoundField DataField="H" HeaderText="H" SortExpression="H" />
<asp:BoundField DataField="HL" HeaderText="HL" SortExpression="HL" />
<asp:BoundField DataField="Weight (Kg)" HeaderText="Weight (Kg)" SortExpression="Weight (Kg)" />
<asp:BoundField DataField="Charge Current(A)" HeaderText="Charge Current(A)" SortExpression="Charge Current(A)" />
<asp:BoundField DataField="Assembly Figure" HeaderText="Assembly Figure" SortExpression="Assembly Figure" />
<asp:BoundField DataField="CCA -18oC" HeaderText="CCA -18oC" SortExpression="CCA -18oC" />
</Columns>
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetGelNano" TypeName="GelNanoTableAdapters.Gel_NanoTableAdapter">
<InsertParameters>
<asp:Parameter Name="Model_No" Type="String" />
<asp:Parameter Name="Alternative_Battery_Ref_" Type="String" />
<asp:Parameter Name="p1" Type="String" />
<asp:Parameter Name="p4" Type="String" />
<asp:Parameter Name="L" Type="String" />
<asp:Parameter Name="W" Type="String" />
<asp:Parameter Name="H" Type="String" />
<asp:Parameter Name="HL" Type="String" />
<asp:Parameter Name="p7" Type="String" />
<asp:Parameter Name="p10" Type="String" />
<asp:Parameter Name="Assembly_Figure" Type="String" />
<asp:Parameter Name="p13" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-22 : 11:55:37
OK, I don't see any template columns and I don't see you trying to output a picture anywhere. Did you try adding a template column?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Richy1
Starting Member

27 Posts

Posted - 2007-05-22 : 12:32:00
Im not entire sure what u mean by a template column - all i have is a small table, with the above data thats linked to SQL server. Its not the biggest table in the world. Now most of the data is text - but one of the column has to be filled with jpgs. These jpgs show the "Assembly Figure" - ie, +, -, +-, arrows, circles, etc, etc.

so all i need to do is have the jpgs in the column. Its really, really simple - i just dont know how to do this. Does that info help? Surely there must be a way so the jpg show up in the screen? There are many different jpgs for each battery.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-22 : 12:34:22
i may have confused you by using the phrase "template column" -- that's what they used to be called in asp.net 1.1. Now they are "template fields", that's what I should have written. Sorry if that caused confusion.

See if this helps:

http://aspnet101.com/aspnet101/tutorials.aspx?id=58

Sounds like you really should brush up on the basic concepts of asp.net gridviews -- I highly recommend reading a good book on asp.net or going through some tutorials on the web. Google will find you lots of them.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Richy1
Starting Member

27 Posts

Posted - 2007-05-23 : 05:01:55
Surely there must be an easier way to do this though? All i need is this exactly - http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=ImageShow#next But thats a Access Database set up, im using Visual Web developer and SQL server.......
Go to Top of Page

Richy1
Starting Member

27 Posts

Posted - 2007-05-23 : 07:41:46
My god its so, sooooo simple -

Have your database set up properly in the DataSet, then a GridView; On the arrow top right in the grid, "Grid View Tasks" and then use "Edit Colums"; remove one of the colums that u want to use as jpgs; then add another column but use the "Imagefield"; Then select "DataImageUrlField" and select which folder that contains the jpgs. Now in the SQL database and the column, simple us "Images/1.jpg" or whatever u want to name the jpgs...and thats it! So, soooooooo simple.....thats all i needed.
Go to Top of Page
   

- Advertisement -