說明:
1.拖曳SqlDataSource至頁面,設定好SQL語法。
2.拖曳GridView至頁面,設定來源為SqlDataSource。
3.請於GridView_PreRender加入以下程式碼。
~relax~
這是一個悠閒放鬆的部落格,請用輕鬆的心情閱讀文章,在忙碌工作之餘療癒自己的身心。
(最近發現我的文章被複製轉貼且沒有註明出處,本部落格的文章皆為原創,若有引用參考也會註明,如有需求請留言告知,謝謝!)
目前分類:C#/VB/ASP.NET (46)
- Jan 12 Wed 2011 17:10
ASP.NET 之 合併GridView儲存格
- Jan 03 Mon 2011 09:09
ASP.NET筆記本 之 DataTable存成CSV,隱藏路徑讓使用者下載檔案
'DataTable存成CSV檔的程式碼---------------------------------- Dim SavePath As String = "C:\Temp\" Dim FileName As String = "Test.csv" Dim FilePath As String = SavePath + FileName Dim sw As New System.IO.StreamWriter(FilePath , False, System.Text.Encoding.Default) '寫入欄位名稱 If MyDataTable.Columns.Count > 0 Then sw.Write(MyDataTable.Columns.Item(0).ColumnName.ToString) End If For i As Integer = 1 To MyDataTable.Columns.Count - 1 sw.Write("," + MyDataTable.Columns.Item(i).ColumnName.ToString) Next sw.Write(sw.NewLine) '寫入各欄位資料 For i As Integer = 0 To MyDataTable.Rows.Count - 1 For j As Integer = 0 To MyDataTable.Columns.Count - 1 If j = 0 Then sw.Write(MyDataTable.Rows(i)(j)) Else sw.Write("," + MyDataTable.Rows(i)(j)) End If Next sw.Write(sw.NewLine) Next sw.Close() '使用SaveAs.aspx隱藏檔案路徑讓使用者下載 Response.Redirect("SaveAs.aspx?filename=" + FileName)
'SaveAs.aspx.vb Page_Load 內的程式碼-------------------------- Dim SavePath As String = "C:\Temp\" Dim FileName As String = Request.QueryString("filename").ToString Dim FilePath As String = SavePath + FileName '設定表頭並存檔 If System.IO.File.Exists(filep) Then With Response .ContentType = "application/save-as" .AddHeader("content-disposition", "attachment; filename=" & FileName) .ContentEncoding = Encoding.UTF8 .WriteFile(FilePath) End With Else Response.Write("no file") End If
'做成Class方便使用 Public Class ExportCSV Function DataTableToCSV(ByVal dt As Data.DataTable, ByVal FileName As String, ByVal SavePath As String) As Boolean Dim FilePath As String = SavePath + FileName Try Dim sw As New System.IO.StreamWriter(FilePath, False, System.Text.Encoding.Default) If dt.Columns.Count > 0 Then sw.Write(dt.Columns.Item(0).ColumnName.ToString) End If For i As Integer = 1 To dt.Columns.Count - 1 sw.Write("," + dt.Columns.Item(i).ColumnName.ToString) Next sw.Write(sw.NewLine) For i As Integer = 0 To dt.Rows.Count - 1 For j As Integer = 0 To dt.Columns.Count - 1 If j = 0 Then sw.Write(dt.Rows(i)(j)) Else sw.Write("," + dt.Rows(i)(j)) End If Next sw.Write(sw.NewLine) Next sw.Close() Catch ex As Exception 'MsgBox(ex.Message) Throw ex End Try If System.IO.File.Exists(FilePath) Then Return True Else Return False End If End Function End Class
'存成CSV檔 Dim SavePath As String = "C:\Temp\" Dim FileName As String = "Test.csv" Dim epCsv As New ExportCSV If epCsv.DataTableToCSV(MyDataTable, FileName, SavePath) = True Then Response.Redirect("SaveAs.aspx?filename=" + FileName) End If
- Dec 14 Tue 2010 10:56
程式語言命名慣例(VB,JAVA,C#)
程式語言命名慣例
Visual Basic:
Visual Basic命名慣例是使用:匈牙利命名法、PascalCasing、camelCasing。
匈牙利命名法:原則將名稱分為兩個部份,字首3個字母小寫為變數之型別,字尾為變數的意義以大小寫混用取名。例:Dim strUserName As String = "Allen",Dim intAge As Integer = 20。
PascalCasing命名法:每個字的第一個字元為大寫,例如:FirstName、LastName。
- Dec 13 Mon 2010 13:14
.NET3.5 C# Multi-Thread 多執行緒
本文參考yc421206-[C#.NET] 如何 使用 多執行緒 Thread / 跨執行緒 存取UI
本文參考catyku-C# Thread應用
前置動作:
using System.Threading;
- Dec 09 Thu 2010 11:07
ASP.NET筆記本 之 GridView編輯驗證+Ajax+一行程式都不用寫
目標:
1.使用SqlDataSource與GridView製作不用撰寫程式碼之頁面。
2.使用Ajax元件讓網頁不閃爍。
3.使用GridView元件編輯功能,並附加使用者輸入資料之驗證功能。
- Nov 26 Fri 2010 10:26
ASP.NET筆記本-常用問答集
asp.net 的圖表元件 chart,可能會遇上「執行 ChartImg.axd 的子要求時發生錯誤」的error...
解決方法就是在web.config裡面,找到以下兩項做修改:(加上POST)
tag:httpHandlers中