Posts

Gridview : Export To Excel ฉบับสมบูรณ์ (แก้บัคภาษาไทยด้วย)

   การเขียนโปรแกรมโดยใช้งาน Control ที่ชื่อว่า Gridview เชื่อได้ว่าทุกคนคงต้องเจอว่า "อยากได้ข้อมูลตารางนี้เป็น Excel ทำไงดี ทำให้พี่หน่อย - -a" ดังนั้นจากประสบการณ์ที่ผ่านมาเจอปัญหาส่วนใหญ่กรณีที่ข้อมูลใน Gridview เป็นภาษาไทย พอทำการ Export จะเจอปัญหาว่า ภาษาไทยเพี้ยนบ้างไรบ้าง ขอสรุปแยกเป็น 2 วิธีการดังนี้ 1. กรณี Gridview ไม่มีการใช้งาน Template Field    1.1) นำ Code ด้านล่าง ไปใส่ที่ปุ่ม Export Excel ได้เลย โดยที่ตั้งชื่อ Gridview เป็น gv Response.ClearContent() Response.AddHeader("content-disposition", "attachment;filename=file.xls") Response.ContentEncoding = System.Text.Encoding.UTF8 Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.xls" Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As New HtmlForm() frm.Attributes("runat") = "server" frm.Controls.Add(gv) gv_Series.RenderControl(...

Using Dynamic Memory in Hyper-V on Windows Server 2008 R2 SP1

Image
การใช้งาน Dynamic Memory ในระบบ Hyper-V บน Windows Server 2008 R2 SP1 Dynamic Memory  เป็นคุณสมบัติใหม่ใน Service Pack 1 (SP1) สำหรับ Windows Server 2008 R2 และ Hyper-V Server 2008 R2 ที่ช่วยให้สามารถใช้งานหน่วยความจำทางกายภาพ (Physical Memory) ในระบบ Hyper-V ได้อย่างมีประสิทธิภาพยิ่งขึ้น มีความเป็นไดนามิกมากขึ้น สามารถรองรับการขยายระบบได้มากขึ้นและง่ายขึ้น โดยก่อนหน้าที่จะมี SP1 นั้น การกำหนดหน่วยความจำให้กับเวอร์ชวลแมชชีน (Virtual machine) ในระบบ Hyper-V จะเป็นแบบคงที่ (Static Memory) หมายความว่าเวอร์ชวลแมชชีนแต่ละตัวจะครอบครองหน่วยความจำที่กำหนดให้ตลอดเวลาที่เปิดเครื่องไม่ว่าเวอร์ชวลแมชชีนจะอยู่ในสถานะทำงานหรือหยุดทำงานชั่วคราวก็ตาม โดยเวอร์ชวลแมชชีนจะคืนหน่วยความจำให้ระบบก็ต่อเมื่ออยู่ในสถานะบันทึกหรือปิดเครื่องเท่านั้น สำหรับเอนทรี่นี้จะสาธิตวิธีการใช้งานคุณสมบัติ Dynamic Memory ในระบบ Hyper-V บน Windows Server 2008 R2 SP1 โดยก่อนอื่นขอแนะนำพารามิเตอร์ต่างๆ ที่เพิ่มขึ้นหลังจากทำการติดตั้ง SP1 ดังนี้ Dynamic Memory: เป็นโหมดใหม่ที่เพิ่มขึ้นมาในหัวข้อ Memory management ใ...

SQL Query Call Web Application

การเขียน SQL Query แบบที่ต้องการรันโปรแกรมที่อยู่บนเว็บ DECLARE @sUrl, @obj int, @response varchar(800) SET @sUrl = "http://server/myapp.aspx" exec sp_OACreate 'WinHttp.WinHttpRequest.5.1', @obj OUT exec sp_OAMethod @obj,'Open',NULL,'GET', @sUrl, false exec sp_OAMethod @obj,'send' exec sp_OAGetProperty @obj,'responseText', @response OUT exec sp_OADestroy @obj

Tip!!! การเขียนโปรแกรมอ้างอิงกรณี Gridview ซ้อน Gridview

   เมื่อทำการเขียนโปรแกรมแล้วเราจะพบปัญหาว่าการเขียนโดยใช้ Gridview1 มี Template Field ที่มี Gridview2 อยู่ในนั้น และใน Gridview2 ก็จะมี Button อยู่ในนั้นด้วย ปัญหาที่เกิดขึ้นจะเจอว่า ถ้าต้องการกดปุ่มดังกล่าวใน Gridview2 แล้วจะอ้างอิงมายัง Gridview1 จะทำอย่างไรดี Protected Sub btn_Button1_Click(sender As Object, e As System.EventArgs)   '-- สร้างปุ่มขึ้นมาเพื่อทำการรองรับปุ่มที่ถูกกดมาจริง   Dim btn_Button1 As Button = CType(sender, Button)    '-- สร้างตัวแปร Gridview1_Row เพื่อดูว่าปุ่ม Button1 นั้นอยู่ใน Row ไหน   Dim GridView1_Row As GridViewRow = CType(btn_Button1.NamingContainer, GridViewRow)   '-- สร้างตัวแปร Gridview1 เพื่อรับ Gridview ใน Gridview1_Row นี้   Dim Gridview1 As GridView = CType(GridView1_Row.NamingContainer, GridView)   '-- สร้างตัวแปร lbl รับ Label Object ใน Gridview1_Row   Dim lbl As Label = CType(GridView1_Row.FindControl("lbl"), Label) End Sub   ในปัญหาเดียวกัน ถ้ามีการซ้อนกันของ Grid...

Automatic Logon

กดปุ่ม WINDOWS + R [ปุ่ม Windows คือปุ่มระหว่าง CTRL และ ALT] ให้พิมพ์ว่า “ netplwiz ” และกด Enter หรือกดปุ่ม OK หลังจากนั้นหน้าต่าง User Accounts จะขึ้นมา ให้เรากดเอาเครืองหมายถูกออกจาก “Users Must enter a user name and password to use this computer” จาก ID ที่เราไม่ต้องการให้มันถามทุกๆครั้งที่ restart. มันจะถามให้ใส่ User และ Password เพื่อยืนยันการเปลี่ยนแปลง เท่านี่ก็เป็นอันเสร็จสิ้น.

File Server :: Transfer to new server with permission

Use robocopy.exe (if less than windows7 then copy robocopy.exe to c:\windows\system32) # Folder and Structure robocopy "\\server\path" "d:\path" /E /lev:2 /E /SEC /XF * # Copy all data in folder robocopy "\\server\path" "d:\path" /E /COPYALL /SEC /PURGE

Client ID & Server ID

Hide TR Tag aspx <table style="width:100%;">    <tr runat="server" id="td1">       <td>1</td>       <td>1</td>       <td>1</td>    </tr>    <tr>       <td>2</td>       <td>2</td>       <td>2</td>    </tr> </table> aspx.vb Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load     td1 .Visible = False End Sub