2010年3月12日 星期五

解決 Jquery + UpdatePanel 產生問題

同時使用Jquery + UpdatePanel 常會發生Jquery只會執行一次
之後就被UpdatePanel的非同步所擋住
雖然新版的Jquery有新增live()的函數
不過好像沒辦法使用在所有的情況下
解決的辦法如下:

//下面為第一次執行的Jquery
jQuery(document).ready(function() {
jQuery("#TextBox4").dynDateTime();
});

//每次進行非同步時,執行下面語法
function load() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest EndRequestHandler);
}
function EndRequestHandler() {
jQuery("#TextBox4").dynDateTime();
}

2010年3月5日 星期五

Just-In-Time 偵錯

使用一般程式出現Just-In-Time 偵錯時解決辦法~
引用自~ http://msdn.microsoft.com/zh-tw/library/5hs4b7a6(VS.80).aspx

在伺服器上安裝 Visual Studio 後,發生未處理例外狀況的預設行為是顯示需要使用者操作的 [例外狀況] 對話方塊,以便啟動 Just-In-Time 偵錯或忽略例外狀況。自動作業則不希望發生這種情況。若要設定伺服器在發生未處理例外狀況時不再顯示對話方塊 (安裝 Visual Studio 之前的預設行為),請使用登錄編輯程式刪除下列登錄機碼:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

在 64 位元作業系統上也請刪除下列登錄機碼:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

2009年12月7日 星期一

Gridview 設定 不斷行、欄位隱藏、設定欄寬

Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Header Then
'不斷行設定
For i As Integer = 0 To e.Row.Cells.Count - 1
e.Row.Cells(i).Attributes.Add("style", "word-break :keep-all ; word-wrap:keep-all")
Next
'欄位隱藏
e.Row.Cells(1).Visible = False
'設定欄寬
e.Row.Cells(0).Attributes.Add("style", "width:20px")
e.Row.Cells(2).Attributes.Add("style", "width:30px")
e.Row.Cells(3).Attributes.Add("style", "width:90px")
e.Row.Cells(4).Attributes.Add("style", "width:90px")
e.Row.Cells(5).Attributes.Add("style", "width:70px")
e.Row.Cells(6).Attributes.Add("style", "width:150px")
End If
End Sub

2009年11月28日 星期六

ASP.NET 產生 匯出 Excel 到Server端

假使要從Client產在一個excel檔到Server端
必須在web.config加上一個有權限執行excel的使用者
如:
<system.web>
<identity impersonate="true" userName ="Administrator" password ="123123"/>
</system.web>

參考自:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022

Try
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Start a new workbook in Excel.
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add

For i As Integer = 0 To ds.Tables.Count - 1
oSheet = oBook.Worksheets.Add
'合併欄位
oSheet.Range("A1", "I1").Merge()
oSheet.Range("J1", "K1").Merge()
'文字置中
oSheet.Range("A1", "I1").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
oSheet.Range("J1", "K1").HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
oSheet.cells(1, 1).Value = "自製工具個人分戶帳"
oSheet.cells(1, 10).Value = "資料日期: " & DateTime.Now.ToShortDateString
oSheet.cells(1, 1).Font.Bold = True
'加入外框線
oSheet.Range("A2", "K" & ds.Tables(i).Rows.Count + 2).Borders.LineStyle = 1
'強制轉型 不加這行的話如果字串是0002 匯到excel會變成2
oSheet.Cells.NumberFormatLocal = "@"
For j As Integer = 0 To ds.Tables(i).Rows.Count - 1
'Add data to cells of the first worksheet in the new workbook.
oSheet.Name = ds.Tables(i).Rows(j).Item(1)
'oSheet.Range("A1").Value = "Last Name"
oSheet.cells(2, 1).Value = "項次"
oSheet.cells(2, 2).Value = "借用人"
oSheet.cells(2, 3).Value = "借用人帳號"
oSheet.cells(j + 3, 1).value = RTrim(ds.Tables(i).Rows(j).Item(0))
oSheet.cells(j + 3, 2).value = RTrim(ds.Tables(i).Rows(j).Item(1))
oSheet.cells(j + 3, 3).value = RTrim(ds.Tables(i).Rows(j).Item(2))
'自動調整欄寬
oSheet.Columns("A:Z").EntireColumn.AutoFit()
Next
Next
'Save the Workbook and quit Excel.
'如果檔案已存在 則自動刪除
If System.IO.File.Exists("C:\" & filename & "borrow.xls") = True Then
System.IO.File.Delete("C:\" & filename & "borrow.xls")
End If
oBook.SaveAs("C:\" & filename & "borrow.xls")

oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()

'KillExcel()
Catch ex As Exception

End Try

如果要強制刪除Excel的程序可用以下語法
不過要注意執行後會強制關掉畫面上所有的excel
Private Sub KillExcel()
Dim myProcesses() As Diagnostics.Process
Dim myProcess As Diagnostics.Process
' Returns array containing all instances of "EXCEL".
On Error Resume Next
myProcesses = Diagnostics.Process.GetProcessesByName("EXCEL")
For Each myProcess In myProcesses
myProcess.Kill()
Next
On Error GoTo 0
myProcesses = Nothing
myProcess = Nothing
End Sub

DataTable 加入流水編號方式

Dim dt as new DataTable
Dim column As New DataColumn("項次", Type.GetType("System.Int32"))
With column
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With
dt.Columns.Add(column)

2009年11月23日 星期一

輸出畫面為千分位 加逗號

SELECT convert(nvarchar,cast('12345.999' as money),1)

2009年11月17日 星期二

如何使 ASP.NET 元件 MENU 能夠更漂亮 CSS

套用以下基本CSS,再依個人審美觀做適當的修改
<asp:Menu ID="Menu1" runat="server" CssClass="menu_Main" DynamicHorizontalOffset="2"
Orientation="Horizontal" StaticSubMenuIndent="10px" Width="296px">
<StaticMenuStyle CssClass ="menu_StaticMenuStyle" />
<StaticMenuItemStyle  CssClass="menu_StaticMenuItemStyle " />
<StaticHoverStyle CssClass="menu_StaticHoverStyle" />
<StaticSelectedStyle CssClass="menu_StaticSelectedStyle"/>
<DynamicMenuStyle CssClass="menu_DynamicMenuStyle" BackColor="#F8F8D4" />
<DynamicSelectedStyle CssClass="menu_DynamicSelectedStyle"  />
<DynamicHoverStyle  CssClass ="menu_DynamicHoverStyle"/>
<Items>
</Items>
</asp:Menu>
/*menu style*/
.menu_Main{
height:30px;
}
.menu_StaticMenuStyle{
}
.menu_StaticMenuItemStyle {
width:70px;
font-size:15px;
/*HorizontalPadding="5px" VerticalPadding="2px"*/
}
.menu_StaticHoverStyle{
color:#FFFFFF;
background-color:#668BB2 ;
width:60px;
}
.menu_StaticSelectedStyle{
}
.menu_DynamicMenuStyle{
font-size:15px;
border-right: #B1B266 thin solid;
border-top: #B1B266 thin solid;
border-left: #B1B266 thin solid;
border-bottom: #B1B266 thin solid ;
z-index: 100;
width:100px;
}
.menu_DynamicMenuItemStyle{
width:200px;
/*HorizontalPadding="5px" VerticalPadding="2px"*/
}
.menu_DynamicSelectedStyle{
}
.menu_DynamicHoverStyle{
color:#FFFFFF;
background-color:#B1B266 ;
width:100px;
}