Current location: Hot Scripts Forums » Programming Languages » ASP » display images in a datagrid or table from mysql database.


display images in a datagrid or table from mysql database.

Reply
  #1 (permalink)  
Old 01-02-05, 11:41 AM
bin bin is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy display images in a datagrid or table from mysql database.

hi everybody...
i'm trying to display images along with the image details stored in mysql database thru my webpage... the best i can do is display one image but no details ... i can retrieve all images as needed and store it someplace but i'm not able to display it

any kind of help will be appreciated...
this is the current code...

Dim con As New OdbcConnection(ConfigurationSettings.AppSettings(" ConnString"))
Dim da As New OdbcDataAdapter("select * from products", con)
Dim CmdB As New OdbcCommandBuilder(da)
Dim ds As New DataSet

Dim arr As Array
con.Open()
da.Fill(ds, "products")

Dim row As DataRow
row = ds.Tables("products").Rows(0)
Dim data() As Byte
Dim k As Long
Dim fs As FileStream
Dim strfilename As String

Response.Buffer = True
Response.ContentType = "image/jpeg"

For Each row In ds.Tables("products").Rows
arr = row.ItemArray
data = row("image")
strfilename = "\Shy\" & arr(0)
k = UBound(data)
fs = New FileStream(strfilename, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(data, 0, k)
Response.BinaryWrite(data)
Next

fs.Close()
fs = Nothing
CmdB = Nothing
ds = Nothing
da = Nothing
con.Close()
Reply With Quote
  #2 (permalink)  
Old 01-03-05, 06:34 PM
bin bin is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Got it!!! herez how to do it for anyone else out there...

wht u do is...
1.make a field in the db which stores the path to the image (which is better than storing actual image in the db)

2.in the datagrid where u want to display the image add a bound column as this field... (do this by property builder). then convert this bound column to template column.

3. on the datagrid right click and select edititemtemplate and the column .
in the column tht appears drop an image control along with the label tht u see in the itemtemplate.

4. in the html page add this
ImageUrl='<%# DataBinder.Eval(Container, "DataItem.imageurl") %>'
in the <img> tag. so that it looks like this....

<asp:TemplateColumn HeaderText="imageurl">
<ItemTemplate>
<asp:Image id=Image4 runat="server" Width="101" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.imageurl") %>' Height="101">
</asp:Image>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.imageurl") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>

5. in code page... fill the datagrid by connection, sql select statement, dataadapter and dataset. and atlast datagrid.databind().
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
Displaying Buttons using DataGrid depending on a DataBase Value - Please Help v1brazy ASP.NET 1 12-08-04 01:25 AM
Can't Display MYSQL Table Kasuki PHP 3 04-05-04 12:20 PM
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM
inserting images into mysql coatsey PHP 3 12-01-03 07:04 PM


All times are GMT -5. The time now is 03:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.