Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > การนำรูปไปโชวใน Gridview โดยเก็บเฉพาะชื่อรูปใน DB และมี pathg เฉพาะในตัวโปรแกรม โดยสามารถอัพโหลดเก็บไฟล์ใน directory ที่ต้องการ



 

การนำรูปไปโชวใน Gridview โดยเก็บเฉพาะชื่อรูปใน DB และมี pathg เฉพาะในตัวโปรแกรม โดยสามารถอัพโหลดเก็บไฟล์ใน directory ที่ต้องการ

 



Topic : 120481



โพสกระทู้ ( 66 )
บทความ ( 0 )



สถานะออฟไลน์




การนำรูปไปโชวใน Gridview โดยเก็บเฉพาะชื่อรูปใน DB และมี pathg เฉพาะในตัวโปรแกรม โดยสามารถอัพโหลดเก็บไฟล์ใน directory ที่ต้องการได้ รบกวนขอคำแนะนำหรือโค้ดดิ่งเบื่องต้นด้วยครับ

เนื่องจากผมมีชื่อรูปใน DB โดยมีรูปแยกเก็บในตัวโฟร์เดอร์ต่างหากแล้ว หากผมต้องการดึง ชื่อรูปจาก db และดึงรูปจากโฟรเดอร์ไปแสดงผลใน Gridview ผมต้องใช้ลักษณคำสั่งแนวไหนครับ รบกวนขอคำชี้เเนะด้วยครับหาตัวอย่างไม่ได้เลย



Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-12-15 10:16:02 By : dendeenarat View : 2286 Reply : 12
 

 

No. 1



โพสกระทู้ ( 66 )
บทความ ( 0 )



สถานะออฟไลน์


https://www.thaicreate.com/dotnet/forum/118192.html
จากกระทู้นี้ก็ยังไม่่เข้าใจครับผม






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-15 15:38:10 By : dendeenarat
 


 

No. 2



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

https://msdn.microsoft.com/en-us/library/aa479350.aspx
แบบนี้ได้ป่าวครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-15 16:11:00 By : lamaka.tor
 

 

No. 3



โพสกระทู้ ( 66 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณสำหรับ ลิงค์นะครับผม
คือผมไม่เข้าใจตรง ที่ว่า
1.ผมจะดึงรูปจาก path ของผมยังไง เช่น C:/interrub/wwwroot/XXX..../ (ปกติเค้าจะทำโพสเดอร์ไว้ใน ตัวโปรแจ็ค แต่ผมต้องการดึงจากนอกโปรแจ็คอะครับ)
2.ผมมีชื่อรูปในดาต้าเบส ผมต้องการให้มันดึง โดยชื่อกับรูปให้ตรงกัน
ตอนนี้งงมากครับ ติดแค่ 2 ข้อนี่อะครับ รบกวนผู้รู้ใจช่วยไขข้อกระจ่างด้วยนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-15 16:37:42 By : dendeenarat
 


 

No. 4



โพสกระทู้ ( 28 )
บทความ ( 0 )



สถานะออฟไลน์


ลองดูเอาครับ WinApp
Code (VB.NET)
 If dt.Rows.Count > 0 Then
            find = True
            ' dt.Columns("productpic").DataType = System.Type.GetType("System.Byte[]")
            'dt.Columns.Add("CarImageData", GetType(Byte()))
            'For Each row As DataRow In dt.Rows
            '    row.SetField(Of Byte())("CarImageData", IO.File.ReadAllBytes(row.Field(Of String)("productpic")))
            'Next
            '*******************สร้าง Column เก็บรูปภาพใน DataGridView****************************************
            dgv1.DataSource = dt
           
            ' If dgv1.Columns.Contains("ColImg") Then
            With dgv1
                .DefaultCellStyle.BackColor = Color.Azure
                .AlternatingRowsDefaultCellStyle.BackColor = Color.White
                .Columns("id").HeaderText = "ID"
                .Columns("productname").HeaderText = "PRODUCT NAME"
                .Columns("dateimport").HeaderText = "DATE IMPORT"
                .Columns("dateexs").HeaderText = "DATE EXISTS"
                .Columns("quantity").HeaderText = "QUANTITY"
                .Columns("price").HeaderText = "PRICE"
                .Columns("unitprice").HeaderText = "UNIT"
                .Columns("productpic").HeaderText = "FILE PATH"
            End With
            ' Else
            'กำหนดความสูงของ Column
            For Each row As DataGridViewRow In dgv1.Rows
                If row.IsNewRow Then Continue For
                row.Height = CInt(row.Height * 5)
            Next
            '  Dim img As New DataGridViewImageCell
            'สร้าง Column ไว้แสดงรูปภาพ
            Dim ColImage As New DataGridViewImageColumn
            If (dgv1.Columns.Contains("ColImg")) Then

            Else
                ColImage.Name = "ColImg"
                ColImage.HeaderText = "PICTURE"
                dgv1.Columns.Add(ColImage)
                'ColImage.ImageLayout = DataGridViewImageCellLayout.Stretch
                ColImage.ImageLayout = DataGridViewImageCellLayout.Zoom
            End If
            'ดึง Path ไฟล์เข้าไปใน DataGridview
            For i As Integer = 0 To dt.Rows.Count - 1
                Dim inImg As Image = Image.FromFile(dt.Rows(i)(7))
                dgv1.Rows(i).Cells("ColImg").Value = inImg
            Next
            '  End If

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-15 18:02:28 By : parinya-t
 


 

No. 5



โพสกระทู้ ( 28 )
บทความ ( 0 )



สถานะออฟไลน์


ตัวอย่างครับ

example
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-16 08:55:20 By : parinya-t
 


 

No. 6



โพสกระทู้ ( 66 )
บทความ ( 0 )



สถานะออฟไลน์


รบกวนขอโค้ดตัวเต็มได้ไหมครับ จะเอาไปศึกษา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-17 10:49:35 By : dendeenarat
 


 

No. 7

Guest


ไม่รู้ได้หรือยังครับ ลองดูนะครับ ถ้ายังไม่ตรงตามความต้องการก็บอกได้นะครับ
Code (VB.NET)
Public Class Form2
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim table = New DataTable()

        Dim ImageColumn As New DataGridViewImageColumn
        With ImageColumn
            .Width = 15
            .DefaultCellStyle.NullValue = Nothing
            .ImageLayout = DataGridViewImageCellLayout.Zoom
        End With

        DataGridView1.Columns.Add(Nothing, "Id")
        DataGridView1.Columns.Add(Nothing, "Product Name")
        DataGridView1.Columns.Add(Nothing, "Picture")
        DataGridView1.Columns.Add(ImageColumn)

        '//create schema
        table.Columns.Add("Id", GetType(Integer))
        table.Columns.Add("ProductName", GetType(String))
        table.Columns.Add("Picture", GetType(String))

        '//add sample rows
        table.Rows.Add(1, "N1", "DSCN6860")
        table.Rows.Add(2, "N2", "DSCN6864")
        table.Rows.Add(3, "N3", "DSCN6865")
        table.Rows.Add(4, "N4", "DSCN6868")
        Dim bmp As Bitmap
        'Dim counter As Integer
        Dim pPaht As String
        For Each row As DataRow In table.Rows
            pPaht = "C:\Users\Bundit\Pictures\" + row.Field(Of String)("Picture") + ".JPG"
            bmp = New Bitmap(pPaht, True)
            DataGridView1.Rows.Add(row.Field(Of Integer)("Id"), row.Field(Of String)("ProductName"), row.Field(Of String)("Picture"), bmp)

        Next
    End Sub

End Class


gridimage
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-17 13:48:40 By : บัญดิษฐ
 


 

No. 8



โพสกระทู้ ( 66 )
บทความ ( 0 )



สถานะออฟไลน์


เนื่องจากผมจะลองประยุกต์ใช้ กับ การดึงข้อมูลจากดาต้าเบส อันนี้เป็นดาต้าเบสที่เก็บชื่อรูปภาพ
11

โดยผมทำบนเว็บแอ๊พครับ นี้เป็นการ join ข้อมูลเพื่อทำการดึงข้อมูล 2 เทเบิ้ลมาร่วมกัน
22

ผมมีโฟรเดอร์ที่เก็บรูปภาพตรง "C:\inetpub\wwwroot\CharmingWS\Pictures\PRODUCT"

ผมยัง งง อยู่ว่าจะนำ Path รูปมาร่วมกับชื่อรูปใน Database ยังไงเพื่อดึงมาโชว์ใน Gridview อะครับ ขอบคุณทุกคำตอบที่คอยช่วยเหลือนะครับ
เดียวจะงม ตามตัวอย่างที่ได้รับดูด้วยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-18 10:29:36 By : dendeenarat
 


 

No. 9



โพสกระทู้ ( 66 )
บทความ ( 0 )



สถานะออฟไลน์


Code (VB.NET)
For Each row As DataRow In table.Rows
            pPaht = "C:\Users\Bundit\Pictures\" + row.Field(Of String)("Picture") + ".JPG"
            bmp = New Bitmap(pPaht, True)
            DataGridView1.Rows.Add(row.Field(Of Integer)("Id"), row.Field(Of String)("ProductName"), row.Field(Of String)("Picture"), bmp)

        Next

ถ้าผมเอามาประยุกต์ใช้กับ webfrom ต้องแก้แบบไหนครับ ลองแล้วไม่ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-18 16:27:19 By : dendeenarat
 


 

No. 10

Guest


Quote:
Server.MapPath specifies the relative or virtual path to map to a physical directory.
•Server.MapPath(".") returns the current physical directory of the file (e.g. aspx) being executed
•Server.MapPath("..") returns the parent directory
•Server.MapPath("~") returns the physical path to the root of the application
•Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)

An example:

Let's say you pointed a web site application (http://www.example.com/) to
C:\Inetpub\wwwroot

and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\WebApps\shop

For example, if you call Server.MapPath in following request:
http://www.example.com/shop/products/GetProduct.aspx?id=2342

then:
•Server.MapPath(".") returns D:\WebApps\shop\products
•Server.MapPath("..") returns D:\WebApps\shop
•Server.MapPath("~") returns D:\WebApps\shop
•Server.MapPath("/") returns C:\Inetpub\wwwroot
•Server.MapPath("/shop") returns D:\WebApps\shop

If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path.

If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the request being processed.

Note: in C#, @ is the verbatim literal string operator meaning that the string should be used "as is" and not be processed for escape sequences.




Tricks

สมมุติว่าชี้ไปที่โฟล์เดอร์ C:\ExternaImages

Code (VB.NET)
<asp:Image ID="imgOutOfProject" ImageUrl="file:///C:/ExternaImages/บักหำ.jpg" runat="server" />

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-18 17:25:30 By : หน้าฮี
 


 

No. 11

Guest


จาก #NO10 เผื่อกึ๋นไม่พอ

ุถ้าเอาขึ้น Server จริง ต้องกำหนดสิทธิ์ให้กับ IUSER ให้สามารถเข้าถึง(อ่าน) โฟล์เดอร์ C:\ExternaImages ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-18 17:34:43 By : หน้าฮี
 


 

No. 12

Guest


จาก #NO10 มีอีก 1 วิธีนั่นคือสร้าง virtual directory บน IIS

"มันอยู่นอกโปรเจคก็หลอกมันว่าอยู่ในโปรเจค"


fixPath2

ปล. จริงฯคิดได้ร้อยแปดพันเก้าแต่พิมพ์ไม่ทัน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-12-18 17:57:56 By : หน้าฮี
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : การนำรูปไปโชวใน Gridview โดยเก็บเฉพาะชื่อรูปใน DB และมี pathg เฉพาะในตัวโปรแกรม โดยสามารถอัพโหลดเก็บไฟล์ใน directory ที่ต้องการ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่