2015年7月27日 星期一

Creating Dynamic Menu From Database SQL Server in ASP.Net

請參考來源:Creating Dynamic Menu From Database SQL Server in ASP.Net
--

HtmlDrive 超多範例

官網: HtmlDrive - Free Dhtml scripts,Jquery plugins,Javascript,CSS,CSS3,Html5 Library
--
這網站太猛了

Dynamic rows - jQuery plugin, which allows you to dynamically append and remove rows containing the html form elements.
--
隨便一個範例都如此驚人!!

ASP.NET jQuery and Database Driven Accordion

參考引用來源:ASP.NET jQuery and Database Driven Accordion
請參考來源:Building a Database Driven Hierarchical Menu using ASP.NET and SooperFish Jquery Plugin

--
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3. <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
  4. <style type="text/css">
  5. .Menu
  6. {
  7. width: 200px;
  8. text-align: center;
  9. border: solid 2px gray;
  10. padding: 0px;
  11. background-color: Silver;
  12. cursor: hand;
  13. font-weight: bold;
  14. }
  15. .MenuItem
  16. {
  17. width: 192px;
  18. text-align: center;
  19. border: solid 1px silver;
  20. padding: 2px;
  21. background-color: whitesmoke;
  22. }
  23. </style>
  24. <script type="text/javascript">
  25. $(document).ready(function() {
  26. $.ajax(
  27. {
  28. type: "POST",
  29. url: "ASPNET jQuery and Database Driven Accordion.aspx/GetMenus",
  30. contentType: "application/json; charset=utf-8",
  31. dataType: "json",
  32. success: CreateMenus,
  33. error: function(err) {
  34. alert(err.status + " - " + err.statusText);
  35. }
  36. });
  37. });
  38. function CreateMenus(results) {
  39. results = results.d;
  40. for (var i = 0; i < results.length; i++) {
  41. $("<div class='Menu'>" + results[i].Text + "</div>")
  42. .click({ MenuId: results[i].MenuId }, OnMenuClick)
  43. .appendTo("#accordionContainer");
  44. }
  45. }
  46. function OnMenuClick(event) {
  47. $("div[id ^= 'menuItemGroup']").slideUp(500);
  48. $.ajax(
  49. {
  50. type: "POST",
  51. url: "ASPNET jQuery and Database Driven Accordion.aspx/GetMenuItems",
  52. data: '{"menuId":"' + event.data.MenuId + '"}',
  53. contentType: "application/json; charset=utf-8",
  54. dataType: "json",
  55. success: function(items) {
  56. items = items.d;
  57. $(event.target).children().remove();
  58. var html = "<div id='menuItemGroup" + event.data.MenuId + "' style='display:none'>";
  59. for (var j = 0; j < items.length; j++) {
  60. html += "<div class='MenuItem'><a href='" + items[j].NavigateUrl + "'>" +
  61. items[j].Text + "</a></div>";
  62. }
  63. html += "</div>";
  64. $(event.target).append(html);
  65. $("#menuItemGroup" + event.data.MenuId).slideDown(500);
  66. },
  67. error: function(err, r, c) {
  68. alert(err.status + " - " + err.statusText);
  69. }
  70. }
  71. )
  72. }
  73. </script>
  74. </head>
  75. <body>
  76. <form id="form1" runat="server">
  77. <div id="accordionContainer">
  78. </div>
  79. </form>
  80. </body>
  81. </html>
---
  1. public class Menu
  2. {
  3. public int MenuId { get; set; }
  4. public string Text { get; set; }
  5. }
  6. public class MenuItem
  7. {
  8. public int MenuId { get; set; }
  9. public int MenuItemId { get; set; }
  10. public string Text { get; set; }
  11. public string NavigateUrl { get; set; }
  12. }
  13. public partial class ASPNET_jQuery_and_Database_Driven_Accordion : System.Web.UI.Page
  14. {
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. }
  18. [System.Web.Services.WebMethod]
  19. public static System.Collections.Generic.List<Menu> GetMenus()
  20. {
  21. System.Collections.Generic.List<Menu> list = new System.Collections.Generic.List<Menu>();
  22. for (int i = 0; i < 6; i++)
  23. {
  24. list.Add(new Menu() {
  25. MenuId= i,
  26. Text = "Menu text "+i.ToString()
  27. });
  28. }
  29. return list;
  30. }
  31. [System.Web.Services.WebMethod]
  32. public static System.Collections.Generic.List<MenuItem> GetMenuItems(int menuId)
  33. {
  34. Random r = new Random();
  35. System.Collections.Generic.List<MenuItem> list = new System.Collections.Generic.List<MenuItem>();
  36. for (int i = 0; i < r.Next(10); i++)
  37. {
  38. MenuItem mi = new MenuItem();
  39. mi.MenuId = menuId;
  40. mi.MenuItemId = i;
  41. mi.Text = "Menu "+ menuId.ToString()+" --- Menu item "+ i.ToString();
  42. mi.NavigateUrl ="http://www.testmenu.com?menuID="+menuId.ToString()+"&MenuItemID="+i.ToString() ;
  43. list.Add(mi);
  44. }
  45. return list;
  46. }
  47. }

收集很多asp.net範例

收集很多asp.net範例
--
可以翻一下唷

jQuery Menu Hover 效果

  1. var obj = null;
  2. function checkHover() {
  3. if (obj) {
  4. $(obj).find(‘ul’).fadeOut(‘fast’);// 淡出效果
  5. }
  6. }
  7. $(document).ready(function () {
  8. $(‘#Nav >li’).hover(function () { // 移入的函數
  9. if (obj) {
  10. obj.find(‘ul’).fadeOut(‘fast’) // 淡出效果
  11. obj = null
  12. }
  13. $(this).find(‘ul’).fadeIn(‘fast’);
  14. }, function () { // 移出的函數
  15. obj = $(this);
  16. setTimeout("checkHover()", 400);
  17. });
  18. });
  19. HTML :
  20. <body>
  21. <ul id="NAV">
  22. <li >Test1
  23. <ul class="menu">
  24. <li><a href="#1">控制台首頁1</a></li>
  25. <li><a href="#2">編輯個人資料1</a></li>
  26. <li><a href="#3">個人空間管理1</a></li>
  27. </ul>
  28. </li>
  29. <li>Test2
  30. <ul class="menu">
  31. <li><a href="#1">控制台首頁2</a></li>
  32. <li><a href="#2">編輯個人資料2</a></li>
  33. <li><a href="#3">個人空間管理2</a></li>
  34. </ul>
  35. </li>
  36. </ul>
  37. </body>
  38. </html>
  39. CSS :
  40. <style type="text/css">
  41. #NAV {width :100px; padding :0px ; list-style :none}
  42. #NAV li { background : #ddd; margin :1x; height :20px}
  43. .menu {padding :0px; margin-top :-18px ; margin-left :98px ;width :202px;list-style :none; display :none}
  44. .menu li {width :202px ; height :20px}
  45. </style>

Request.Pash去讀取網址後的參數

語 法 結 果
Request.ApplicationPath /
Request.PhysicalPath D:\Projects\Solution\web\minwt\doc\detail.aspx
System.IO.Path.GetDirectoryName
(Request.PhysicalPath) D:\Projects\Solution\web\minwt\doc
Request.PhysicalApplicationPath D:\Projects\Solution\web\
System.IO.Path.GetFileName
(Request.PhysicalPath) detail.aspx
Request.CurrentExecutionFilePath /minwt/doc/detail.aspx
Request.FilePath /minwt/doc/detail.aspx
Request.Path /minwt/doc/detail.aspx/123
Request.RawUrl /minwt/doc/detail.aspx/123?id=1
Request.Url.AbsolutePath /minwt/doc/detail.aspx/123
Request.Url.AbsoluteUri http://localhost/minwt/doc/detail.aspx/123?id=1
Request.Url.Scheme http
Request.Url.Host localhost
Request.Url.Port 1897
Request.Url.Authority localhost:1897
Request.Url.LocalPath /minwt/doc/detail.aspx/123
Request.PathInfo /123
Request.Url.PathAndQuery /minwt/doc/detail.aspx/123?id=1
Request.Url.Query ?id=1
Request.Url.Segments /
minwt/
doc/
detail.aspx/
123

240多個jQuery插件 的連結範例

強烈推薦:240多個jQuery插件
---
真是超多,可以運用了

圖形驗證碼控制項

[ASP.NET 控制項實作 Day28] 圖形驗證碼控制項
---

NET Magazine國際中文電子雜誌

NET-Magazine國際中文電子雜誌
整合ASP.NET Web Forms與Bootstrap -1
整合jQuery UI 與ASP. NET Web Form - 1
整合jQuery UI 與ASP. NET Web Form - 2
整合jQuery UI 與ASP. NET Web Form - 3
---
該好好學習了

使用jQuery的Ajax存取資料(ashx,aspx,asmx)

請參考來源:[ASP.NET & jQuery]使用jQuery的Ajax存取資料(ashx,aspx,asmx)
--
這篇不錯!!

ASP.NET與影音資料庫課程總整理

吳老師教學部落格: ASP.NET與影音資料庫課程總整理
---
好像不錯的基礎教學!! 有空可參考一下

2015年7月20日 星期一

POS Print in VB.NET ( Raw Print )

參考引用來源:POS Print in VB.NET ( Raw Print )
--
Create new class :

Imports System.IO
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices

Public Class RawPrinterHelper
' Structure and API declarions:
_
Structure DOCINFOW
Public pDocName As String
Public pOutputFile As String
Public pDataType As String
End Structure

SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As Long) As Boolean
End Function
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(ByVal hPrinter As IntPtr, ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function WritePrinter(ByVal hPrinter As IntPtr, ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As Int32) As Boolean
End Function

' SendBytesToPrinter()
' When the function is given a printer name and an unmanaged array of
' bytes, the function sends those bytes to the print queue.
' Returns True on success or False on failure.
Public Shared Function SendBytesToPrinter(ByVal szPrinterName As String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
Dim hPrinter As IntPtr      ' The printer handle.
Dim dwError As Int32        ' Last error - in case there was trouble.
Dim di As DOCINFOW          ' Describes your document (name, port, data type).
Dim dwWritten As Int32      ' The number of bytes written by WritePrinter().
Dim bSuccess As Boolean     ' Your success code.

' Set up the DOCINFO structure.
With di
.pDocName = "My Visual Basic .NET RAW Document"
.pDataType = "RAW"
End With
' Assume failure unless you specifically succeed.
bSuccess = False
If OpenPrinter(szPrinterName, hPrinter, 0) Then
If StartDocPrinter(hPrinter, 1, di) Then
If StartPagePrinter(hPrinter) Then
' Write your printer-specific bytes to the printer.
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, dwWritten)
EndPagePrinter(hPrinter)
End If
EndDocPrinter(hPrinter)
End If
ClosePrinter(hPrinter)
End If
' If you did not succeed, GetLastError may give more information
' about why not.
If bSuccess = False Then
dwError = Marshal.GetLastWin32Error()
End If
Return bSuccess
End Function ' SendBytesToPrinter()

' SendFileToPrinter()
' When the function is given a file name and a printer name,
' the function reads the contents of the file and sends the
' contents to the printer.
' Presumes that the file contains printer-ready data.
' Shows how to use the SendBytesToPrinter function.
' Returns True on success or False on failure.
Public Shared Function SendFileToPrinter(ByVal szPrinterName As String, ByVal szFileName As String) As Boolean
' Open the file.
Dim fs As New FileStream(szFileName, FileMode.Open)
' Create a BinaryReader on the file.
Dim br As New BinaryReader(fs)
' Dim an array of bytes large enough to hold the file's contents.
Dim bytes(fs.Length) As Byte
Dim bSuccess As Boolean
' Your unmanaged pointer.
Dim pUnmanagedBytes As IntPtr

' Read the contents of the file into the array.
bytes = br.ReadBytes(fs.Length)
' Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem(fs.Length)
' Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, fs.Length)
' Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, fs.Length)
' Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoTaskMem(pUnmanagedBytes)
Return bSuccess
End Function ' SendFileToPrinter()

' When the function is given a string and a printer name,
' the function sends the string to the printer as raw bytes.
Public Shared Function SendStringToPrinter(ByVal szPrinterName As String, ByVal szString As String)
Dim pBytes As IntPtr
Dim dwCount As Int32
' How many characters are in the string?
dwCount = szString.Length()
' Assume that the printer is expecting ANSI text, and then convert
' the string to ANSI text.
pBytes = Marshal.StringToCoTaskMemAnsi(szString)
' Send the converted ANSI string to the printer.
SendBytesToPrinter(szPrinterName, pBytes, dwCount)
Marshal.FreeCoTaskMem(pBytes)
End Function
End Class
How to using the class ?

     Public Sub PrintingOut()
        Dim s As String

        Dim pd As New PrintDialog()

        ' You need a string to send.
        s = "Hello, this is a test"
        ' Open the printer dialog box, and then allow the user to select a printer.
        pd.PrinterSettings = New PrinterSettings()
        If (pd.ShowDialog() = DialogResult.OK) Then
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s)

        End If
    End Sub
Varible “s” can be assign POS code, this is example :

Public sess_ESC As String = ChrW(27) + "!"
Public sess_EPSON_BOLD_ON As String = sess_ESC + Chr(16) + sess_ESC + Chr(32)
Public sess_EPSON_BOLD_OFF As String = sess_ESC + Chr(0) + sess_ESC + Chr(0)
Public sess_STAR_BOLD_ON As String = sess_ESC + Chr(14) + sess_ESC + Chr(15)
Public sess_STAR_BOLD_OFF As String = sess_ESC + Chr(4) + sess_ESC + Chr(5)

Public sess_PRINT_BOLD_ON As String = sess_ESC + Chr(17)
Public sess_PRINT_BOLD_OFF As String = sess_ESC + Chr(0)
Example making bold text :

s = "  .: Parking System :. " & vbCrLf
s &= dtInfo(1) & vbCrLf
s &= dtInfo(2) & ", " & dtInfo(3) & vbCrLf
s &= dtInfo(5) & vbCrLf
s &= "================================" & vbCrLf
s &= "   GATE   OPERATOR    " & vbCrLf
s &= "   " & sess_gate & "   " & sess_fullname & " - " & sess_username & vbCrLf
s &= "IN  : " & dtTable(6) & vbCrLf
s &= "    " & dtTable(0) & vbCrLf

's &= FontStyle.Bold
s &= sess_PRINT_BOLD_ON

s &= "    " & dtTable(1) & vbCrLf
s &= "    Rp. " & Format(total, "#,##0.00") & vbCrLf

s &= sess_PRINT_BOLD_OFF

s &= "OUT : " & getnow & vbCrLf
s &= "    " & dtTable(12) & vbCrLf
s &= "    " & dtTable(2) & vbCrLf
s &= "================================" & vbCrLf
s &= "Terima Kasih Atas Kunjungan Anda" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "" & vbCrLf
s &= "_" & vbCrLf

2015年7月10日 星期五

SQL Server 瀏覽 trc 檔 (Log)

請參考來源
--
(1)
Example:
SELECT *
FROM fn_trace_getinfo(1)

(2)
SELECT T.eventid AS [id], E.name
FROM fn_trace_geteventinfo(1) T
  JOIN sys.trace_events E
  ON T.eventid = E.trace_event_id
GROUP BY T.eventid, E.name

(3)
SELECT *
FROM fn_trace_gettable
('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log.trc', default)

mssql 重設欄位屬性及是否允許NULL

參考來源
--
ALTER TABLE tablename ALTER COLUMN fieldname datatype NOT NULL

Javascript呼叫IE列印以及預覽列印的方法

引用來源
--

  1. 整頁列印:
  2. html部分:
  3. <INPUT TYPE="button" value="整頁列印" onclick="print()">
  4. Javascript部分:
  5. N/A
  6. 部分列印(只列印div包起來的網頁):
  7. html部分:
  8. <div id="block">
  9. <P><img id="ruten" name="ruten" SRC="http://www.ruten.com.tw/imgs/2008/logo.gif"></P>
  10. </div>
  11. <input type="button" value="部分列印" onclick="printScreen(block)">
  12. Javascript部分:
  13. //列印div包起來的部分並且列印完畢後自動關閉列印網頁
  14. function printScreen(block){
  15. var value = block.innerHTML;
  16. var printPage = window.open("","printPage","");
  17. printPage.document.open();
  18. printPage.document.write("<HTML><head></head><BODY onload='window.print();window.close()'>");
  19. printPage.document.write("<PRE>");
  20. printPage.document.write(value);
  21. printPage.document.write("</PRE>");
  22. printPage.document.close("</BODY></HTML>");
  23. }
  24. 整頁預覽列印:
  25. html部分:
  26. <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
  27. <INPUT TYPE="button" value="整頁預覽" onclick="javascript:wb.execwb(7,1)">
  28. Javascript部分:
  29. N/A
  30. 部分預覽列印(只預覽div包起來的部份):
  31. html部分:
  32. <div id="block">
  33. <P><img id="ruten" name="ruten" SRC="http://www.ruten.com.tw/imgs/2008/logo.gif"></P></div>
  34. <input type="button" value="區塊預覽" onclick="previewScreen(block)">
  35. Javascript部分:
  36. //預覽div包起來的部分並且列印完畢後自動關閉列印網頁
  37. function previewScreen(block){
  38. var value = block.innerHTML;
  39. var printPage = window.open("","printPage","");
  40. printPage.document.open();
  41. printPage.document.write("<OBJECT classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2' height=0 id=wc name=wc width=0></OBJECT>");
  42. printPage.document.write("<HTML><head></head><BODY onload='javascript:wc.execwb(7,1);window.close()'>");
  43. printPage.document.write("<PRE>");
  44. printPage.document.write(value);
  45. printPage.document.write("</PRE>");
  46. printPage.document.close("</BODY></HTML>");
  47. }

asp.net 列印網頁

  1. asp.net 列印網頁
  2. 方法一:透過 webbrowser 物件
  3. document.all.WebBrowser.ExecWB(1,1) //打開
  4. document.all.WebBrowser.ExecWB(2,1) //關閉全部
  5. document.all.WebBrowser.ExecWB(4,1) //另存為
  6. document.all.WebBrowser.ExecWB(6,1) //列印
  7. document.all.WebBrowser.ExecWB(6,6) //直接列印
  8. document.all.WebBrowser.ExecWB(7,1) //預覽列印
  9. document.all.WebBrowser.ExecWB(8,1) //頁面設置
  10. document.all.WebBrowser.ExecWB(10,1) //屬性
  11. document.all.WebBrowser.ExecWB(17,1) //全選
  12. document.all.WebBrowser.ExecWB(22,1) //刷新
  13. document.all.WebBrowser.ExecWB(45,1) //關閉
  14. 方法二:直接用 javascript
  15. window.print();
  16. 方法三:寫一個JS檔,搭配前端 button 的觸發,列印指定 DIV 的區塊
  17. <title>列印頁面測試</title>
  18. <script type="text/javascript" src="print.js"></script>
  19. </head>
  20. <asp:Button ID="Button1" runat="server" Text="Button" Height="61px" onclientclick="printScreen(print_parts)" Width="248px" onclick="Button1_Click" />
  21. print.js
  22. function printScreen(printlist)
  23. {
  24. var value = printlist.innerHTML;
  25. var printPage = window.open("", "Printing...", "");
  26. printPage.document.open();
  27. printPage.document.write("<HTML><head></head><BODY onload='window.print();window.close()'>");
  28. printPage.document.write("<PRE>");
  29. printPage.document.write(value);
  30. printPage.document.write("</PRE>");
  31. printPage.document.close("</BODY></HTML>");
  32. }
  33. protected void Button1_Click(object sender, EventArgs e)
  34. {
  35. Page.ClientScript.RegisterClientScriptInclude("myPrint", "print.js");
  36. }

2015年7月4日 星期六

在 Server 端存取 Excel 檔案的利器:NPOI Library

msdn:在 Server 端存取 Excel 檔案的利器:NPOI Library
--

ASP.NET 即時產生縮圖

參考引用來源:[ASP.NET] 即時產生縮圖
--
需求:傳入圖片網址,產生即時縮圖。
可依需求做在一隻檔案裡面 .. 有需要就傳值給它去處理。 (這隻檔案 ContentType 會是 image/Jpeg)
需 Import 進下列 Namespace:
Imports System.Drawing
Imports System.Net
Imports System.IO
Imports System.Web

'''
    ''' 不儲存縮圖的即時繪製縮圖方法
    '''
    ''' 圖檔網址
    '''
    '''
    '''
    '''
Public Function renderThumb(ByVal durl As String, ByVal w As Integer, ByVal h As Integer)

    Dim width, height As Integer

    Dim wc As WebClient = New WebClient()
    Dim ms As MemoryStream = New MemoryStream(wc.DownloadData(durl))
    Dim image As System.Drawing.Image = New Bitmap(ms)

    width = image.Width
    height = image.Height


    If Not (width < w And height < h) Then
        If width > height Then
            h = w * height / width
        Else
            w = h * width / height
        End If
    End If


    Dim img As System.Drawing.Bitmap = New System.Drawing.Bitmap(w, h)
    Dim graphic As Graphics = Graphics.FromImage(img)
    graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
    graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
    graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
    graphic.DrawImage(image, 0, 0, w, h)

    image.Dispose()

    Dim ms_r As New System.IO.MemoryStream()
    img.Save(ms_r, System.Drawing.Imaging.ImageFormat.Jpeg)
    HttpContext.Current.Response.ClearContent()
    HttpContext.Current.Response.ContentType = "image/Jpeg"
    HttpContext.Current.Response.BinaryWrite(ms_r.ToArray())

    img.Dispose()
    graphic.Dispose()

End Function

2015年7月1日 星期三

asp.net 電子教學檔(學校)

學校的asp.net 電子教學檔 ppt
---
很基礎的電子檔,有空可多看看;練練基本功!

asp.net 動態產生CheckBox

參考引用來源
--

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Partial Class Default4
Inherits System.Web.UI.Page
Private WorkMch As String() = {"A", "B", "C", "D", "E", "F", _
"G", "H"}
'CheckBox的Text
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Page.Load
If Not IsPostBack Then
AddControls()
End If
End Sub


Protected Overrides Sub LoadViewState(savedState As Object)
MyBase.LoadViewState(savedState)
'ViewState["controsladded"]似乎是由base繼承下來的,不可更改
If ViewState("controsladded") Is Nothing Then
AddControls()
End If
End Sub


Private Sub AddControls()
pnlCheckbox.Controls.Add(New LiteralControl(""))

Dim i As Integer = 0
While i < WorkMch.Length
Dim l_cbx As New CheckBox()
l_cbx.Text = WorkMch(i).ToString()
l_cbx.ID = "cbx" + WorkMch(i).ToString()
l_cbx.AutoPostBack = True
'pnlCheckbox為Panel控制項
pnlCheckbox.Controls.Add(New LiteralControl(""))
pnlCheckbox.Controls.Add(l_cbx)
pnlCheckbox.Controls.Add(New LiteralControl("
"))
If i > 0 AndAlso i Mod 4 = 3 AndAlso i <> WorkMch.Length - 1 Then
pnlCheckbox.Controls.Add(New LiteralControl("
")) ElseIf i = WorkMch.Length - 1 Then
pnlCheckbox.Controls.Add(New LiteralControl("
")) End If
'為自訂的checkbox掛上event
AddHandler l_cbx.CheckedChanged, New EventHandler(AddressOf(l_cbx_CheckedChanged))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
pnlCheckbox.Controls.Add(New LiteralControl("
")) ViewState("controlsadded") = True
End Sub


Private Sub l_cbx(sender As Object, e As System.EventArgs) Handles l.cbx
Dim cbx As CheckBox = CType(sender, CheckBox)
Response.Write("CheckBox" + cbx.Text + " : " + cbx.Checked.ToString())
End Sub


Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim cbxA As New CheckBox()
cbxA = CType(pnlCheckbox.FindControl("cbxA"), CheckBox)
Response.Write(cbxA.Checked)
End Sub


Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
pnlCheckbox.Controls.Clear()
End Sub


End Class