說明:因GridView內控制項(label)文字太長,想設定斷行。
作法:
1. 在GridView的RowDataBound事件內,找到該控制項。
2. 再設定特定長度或字元斷行,例:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblTest = (Label)e.Row.FindControl("lblTest");
if (lblTest .Text.Length > 0)
{
//1. 直接insert <br/>
blTest.Text = (lblTestt.Text.IndexOf('.') > 0) ? lblTest.Text.Insert(lblTestt.Text.IndexOf('.') + 1, "<br/>") : blTest.Text;
// 2. 用replace加入<br/>
lblTest.Text = lblTest.Text.Replace(".", ".<br/>");
}
}
}
參考資料:
http://www.dreamincode.net/forums/topic/117242-wrapping-around-a-symbol/
http://msdn.microsoft.com/zh-tw/library/11w09h50(v=vs.110).aspx
2014年7月30日 星期三
2014年7月21日 星期一
[Oracle/Toad] 如何在toad測試function與procedure
說明:在修改完function或procedure (schema Browser -> copy script to an Editor Window)後,要如何測試呢?
作法:
測試function:
1. Menu -> View -> 打開DBMS Output
2. 在Editor視窗輸入如下語法:
begin
parameter := '測試資料';
dbms_output.put_line(packagename.functionname(parameter));
commit;
end;
3. return值會顯示於DBMS Output視窗上
或SELECT function FROM dual;
測試procedure:
1. schema Browser -> Tab Source上右鍵 -> Execute Procedure (或copy code到Editor執行)
2. SELECT procedure FROM dual;
參考資料:
http://stackoverflow.com/questions/4827134/how-do-i-get-the-return-value-from-a-function-in-oracle-using-toad
http://www.dotblogs.com.tw/kim/archive/2011/06/01/26827.aspx
http://blog.yam.com/csylvia/article/71505909
http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
http://plsql-tutorial.com/plsql-functions.htm
http://blog.yam.com/csylvia/article/71505909
http://godleon.blogspot.tw/2008/12/oracle-stored-procedures.html
作法:
測試function:
1. Menu -> View -> 打開DBMS Output
2. 在Editor視窗輸入如下語法:
begin
parameter := '測試資料';
dbms_output.put_line(packagename.functionname(parameter));
commit;
end;
3. return值會顯示於DBMS Output視窗上
或SELECT function FROM dual;
測試procedure:
1. schema Browser -> Tab Source上右鍵 -> Execute Procedure (或copy code到Editor執行)
2. SELECT procedure FROM dual;
參考資料:
http://stackoverflow.com/questions/4827134/how-do-i-get-the-return-value-from-a-function-in-oracle-using-toad
http://www.dotblogs.com.tw/kim/archive/2011/06/01/26827.aspx
http://blog.yam.com/csylvia/article/71505909
http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
http://plsql-tutorial.com/plsql-functions.htm
http://blog.yam.com/csylvia/article/71505909
http://godleon.blogspot.tw/2008/12/oracle-stored-procedures.html
2014年7月17日 星期四
[AJAX] 使用ASP.NET Ajax與jQuery Ajax實作連動下拉式選單
說明:
使用ASP.NET Ajax與jQuery Ajax實作兩個下拉式選單,第一個為地區(id: ddlArea),第二個顯示對應地區的縣市(id: ddlCounty)。
作法:
使用ASP.NET Ajax:
1. .NET 3.5已內建ASP.NET Ajax,若是更舊版本需自行import Ajax Extensions。
2. 從工具箱拉ScriptManager與UpdatePanel控制項,然後將ddlCounty放進UpdatePanel內,
並設定Triggers為ddlArea,例:
xxx.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" >
</asp:ScriptManager>
<asp:DropDownList ID="ddlArea" runat="server" AutoPostBack="true" onselectedindexchanged="ddlArea_SelectedIndexChanged"></asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlCounty" runat="server"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlArea"
EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
xxx.aspx.cs
protected void ddlArea_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ddlArea.SelectedIndex > 0)
{
DataTable dtCounty = 資料來源;
this.ddlCounty.DataSource = dtCounty;
this.ddlCounty.DataTextField = "County_Name";
this.ddlCounty.DataValueField = "County_No";
this.ddlCounty.DataBind();
}
}
使用jQuery Ajax (後端使用webservice):
1. 在webservice新增webmethod供ajax存取,例:
//WebService.cs
public class AreaInfo
{
public string AreaNo { get; set; }
public string AreaName { get; set; }
}
public class CountyInfo
{
public string CountyNo { get; set; }
public string CountyName { get; set; }
}
[WebMethod]
public List<AreaInfo> LoadArea()
{
List<AreaInfo> AreaInfo1 = new List<AreaInfo>();
DataTable dtResult = 資料來源;
if (dtResult != null && dtResult.Rows.Count > 0)
{
for (int i = 0; i < dtResult.Rows.Count; i++)
{
AreaInfo1.Add(new AreaInfo()
{
AreaNo = dtResult.Rows[i]["Area_No"].ToString(),
AreaName = dtResult.Rows[i]["Area_Name"].ToString()
});
}
}
return AreaInfo1;
}
[WebMethod]
public List<CountyInfo> LoadCounty(string strAreaNo)
{
List<CountyInfo> CountyInfo1 = new List<CountyInfo>();
DataTable dtResult = 資料來源;
if (dtResult != null && dtResult.Rows.Count > 0)
{
for (int i = 0; i < dtResult.Rows.Count; i++)
{
CountyInfo1.Add(new CountyInfo()
{
CountyNo = dtResult.Rows[i]["County_No"].ToString(),
CountyName = dtResult.Rows[i]["County_Name"].ToString()
});
}
}
return CountyInfo1;
}
2. include jQuery library並使用jQuery.ajax跟後端要資料(回傳格式使用json),例:
//xxx.aspx
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: 'post',
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/LoadArea",
data: "{}",
dataType: "json",
success: function(Result) {
$.each(Result.d, function(key, value) {
$("#ddlArea").append($("<option></option>").val(value.AreaNo).html(value.AreaName));
});
},
error: function() { alert('ajax fail'); }
});
$('#ddlArea').change(function() {
$("#ddlCounty").find('option').remove();
var ID = $(this).val();
$.ajax({
type: 'post',
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/LoadCounty",
data: "{strAreaNo:" + ID + "}",
dataType: "json",
success: function(Result) {
$.each(Result.d, function(key, value) {
$("#ddlCounty").append($("<option></option>").val(value.CountyNo).html(value.CountyName));
});
},
error: function() { alert('ajax fail'); }
});
});
});
</script>
<asp:DropDownList ID="ddlArea" runat="server"></asp:DropDownList>
<asp:DropDownList ID="ddlCounty" runat="server"></asp:DropDownList>
參考資料:
http://stackoverflow.com/questions/10477476/why-0-in-textbox10-value-is-used-to-get-scalar-value-in-asp-net-control
http://www.dotblogs.com.tw/hatelove/archive/2009/12/22/jqueryajax.aspx
http://msdn.microsoft.com/zh-tw/dd310332.aspx#jQuery
http://www.dotblogs.com.tw/topcat/category/1656.aspx
http://pastie.org/2356308
http://social.msdn.microsoft.com/Forums/zh-TW/384800f1-d366-484e-bd30-aaeac5d07d85/aspnet-jqueryjqueryajaxashxaspxasmx?forum=236#9125942a-cc8a-41d5-981e-882fe0894f82
https://www.youtube.com/playlist?list=PLNPgPJ-90sSlwfSHvuyafzWJ8jQphAam0
http://www.codeproject.com/Tips/688228/Bind-Dropdownlist-in-ASP-NET-using-jQuery-AJAX
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
使用ASP.NET Ajax與jQuery Ajax實作兩個下拉式選單,第一個為地區(id: ddlArea),第二個顯示對應地區的縣市(id: ddlCounty)。
作法:
使用ASP.NET Ajax:
1. .NET 3.5已內建ASP.NET Ajax,若是更舊版本需自行import Ajax Extensions。
2. 從工具箱拉ScriptManager與UpdatePanel控制項,然後將ddlCounty放進UpdatePanel內,
並設定Triggers為ddlArea,例:
xxx.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" >
</asp:ScriptManager>
<asp:DropDownList ID="ddlArea" runat="server" AutoPostBack="true" onselectedindexchanged="ddlArea_SelectedIndexChanged"></asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlCounty" runat="server"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlArea"
EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
xxx.aspx.cs
protected void ddlArea_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ddlArea.SelectedIndex > 0)
{
DataTable dtCounty = 資料來源;
this.ddlCounty.DataSource = dtCounty;
this.ddlCounty.DataTextField = "County_Name";
this.ddlCounty.DataValueField = "County_No";
this.ddlCounty.DataBind();
}
}
使用jQuery Ajax (後端使用webservice):
1. 在webservice新增webmethod供ajax存取,例:
//WebService.cs
public class AreaInfo
{
public string AreaNo { get; set; }
public string AreaName { get; set; }
}
public class CountyInfo
{
public string CountyNo { get; set; }
public string CountyName { get; set; }
}
[WebMethod]
public List<AreaInfo> LoadArea()
{
List<AreaInfo> AreaInfo1 = new List<AreaInfo>();
DataTable dtResult = 資料來源;
if (dtResult != null && dtResult.Rows.Count > 0)
{
for (int i = 0; i < dtResult.Rows.Count; i++)
{
AreaInfo1.Add(new AreaInfo()
{
AreaNo = dtResult.Rows[i]["Area_No"].ToString(),
AreaName = dtResult.Rows[i]["Area_Name"].ToString()
});
}
}
return AreaInfo1;
}
[WebMethod]
public List<CountyInfo> LoadCounty(string strAreaNo)
{
List<CountyInfo> CountyInfo1 = new List<CountyInfo>();
DataTable dtResult = 資料來源;
if (dtResult != null && dtResult.Rows.Count > 0)
{
for (int i = 0; i < dtResult.Rows.Count; i++)
{
CountyInfo1.Add(new CountyInfo()
{
CountyNo = dtResult.Rows[i]["County_No"].ToString(),
CountyName = dtResult.Rows[i]["County_Name"].ToString()
});
}
}
return CountyInfo1;
}
2. include jQuery library並使用jQuery.ajax跟後端要資料(回傳格式使用json),例:
//xxx.aspx
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: 'post',
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/LoadArea",
data: "{}",
dataType: "json",
success: function(Result) {
$.each(Result.d, function(key, value) {
$("#ddlArea").append($("<option></option>").val(value.AreaNo).html(value.AreaName));
});
},
error: function() { alert('ajax fail'); }
});
$('#ddlArea').change(function() {
$("#ddlCounty").find('option').remove();
var ID = $(this).val();
$.ajax({
type: 'post',
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/LoadCounty",
data: "{strAreaNo:" + ID + "}",
dataType: "json",
success: function(Result) {
$.each(Result.d, function(key, value) {
$("#ddlCounty").append($("<option></option>").val(value.CountyNo).html(value.CountyName));
});
},
error: function() { alert('ajax fail'); }
});
});
});
</script>
<asp:DropDownList ID="ddlArea" runat="server"></asp:DropDownList>
<asp:DropDownList ID="ddlCounty" runat="server"></asp:DropDownList>
參考資料:
http://stackoverflow.com/questions/10477476/why-0-in-textbox10-value-is-used-to-get-scalar-value-in-asp-net-control
http://www.dotblogs.com.tw/hatelove/archive/2009/12/22/jqueryajax.aspx
http://msdn.microsoft.com/zh-tw/dd310332.aspx#jQuery
http://www.dotblogs.com.tw/topcat/category/1656.aspx
http://pastie.org/2356308
http://social.msdn.microsoft.com/Forums/zh-TW/384800f1-d366-484e-bd30-aaeac5d07d85/aspnet-jqueryjqueryajaxashxaspxasmx?forum=236#9125942a-cc8a-41d5-981e-882fe0894f82
https://www.youtube.com/playlist?list=PLNPgPJ-90sSlwfSHvuyafzWJ8jQphAam0
http://www.codeproject.com/Tips/688228/Bind-Dropdownlist-in-ASP-NET-using-jQuery-AJAX
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
2014年6月11日 星期三
[C#] 加入參考Microsoft.office.core的dll
做法:
加入參考->選取COM tab ->找到Microsoft Office (1x.0) Object Library
參考資料:
http://social.msdn.microsoft.com/Forums/en-US/6fef9910-fed8-4b13-9366-66d24c0966a7/microsoftofficecoredll-location
2014年5月30日 星期五
[ASP.NET] a potentially dangerous request.form value was detected from the client
說明:ASP.NET 4.0,另開新視窗時,出現錯誤訊息:a potentially dangerous request.form value was detected from the client,是避免XSS (Cross-site scripting)攻擊(一種夾帶script語法到網頁的方式)的訊息,所以偵測到post <或>字元,就會出現此訊息。
解決方法:
1.在web.config的<system.web></system.web>標籤中加上 <httpRuntime requestValidationMode="2.0" />與<pages validateRequest="false" />,因為ASP.NET 2.0 request validation的順序會在request processing events之後,若限個別pages,可在各pages加上<@ Page validateRequest="false" %>,但此方法不推薦。
2. 使用HttpUtility.HtmlEncode (Server.HtmlEncode)或AntiXss.HtmlEncode (import AntiXssLibrary.dll),會將特殊字元編碼HTML字元集,如<換為<,"換為",供HTML正常輸出。
參考資料:
http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client
http://www.asp.net/whitepapers/aspnet4/breaking-changes
http://msdn.microsoft.com/en-us/library/hh882339.aspx
http://msdn.microsoft.com/en-us/library/aa973813.aspx
http://msdn.microsoft.com/en-us/library/ms998274.aspx
http://www.dotblogs.com.tw/johnny/archive/2010/03/01/13829.aspx
http://www.dotblogs.com.tw/coca/archive/2011/03/11/21794.aspx
http://blog.darkthread.net/post-2008-06-18-eval-xss.aspx
解決方法:
1.在web.config的<system.web></system.web>標籤中加上 <httpRuntime requestValidationMode="2.0" />與<pages validateRequest="false" />,因為ASP.NET 2.0 request validation的順序會在request processing events之後,若限個別pages,可在各pages加上<@ Page validateRequest="false" %>,但此方法不推薦。
2. 使用HttpUtility.HtmlEncode (Server.HtmlEncode)或AntiXss.HtmlEncode (import AntiXssLibrary.dll),會將特殊字元編碼HTML字元集,如<換為<,"換為",供HTML正常輸出。
參考資料:
http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client
http://www.asp.net/whitepapers/aspnet4/breaking-changes
http://msdn.microsoft.com/en-us/library/hh882339.aspx
http://msdn.microsoft.com/en-us/library/aa973813.aspx
http://msdn.microsoft.com/en-us/library/ms998274.aspx
http://www.dotblogs.com.tw/johnny/archive/2010/03/01/13829.aspx
http://www.dotblogs.com.tw/coca/archive/2011/03/11/21794.aspx
http://blog.darkthread.net/post-2008-06-18-eval-xss.aspx
2014年5月7日 星期三
[Oracle] Windows環境下手動移除Oracle client
作法:
1. 使用Oracle Universal Installer (OUI)移除Oracle全部安裝程式。
2. 開始->執行regedit.exe->刪除HKEY_LOCAL_MACHINE/SOFTWARE/Oracle登錄檔。
3. 如果windows是64位元,需再刪HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Oracle登錄檔,如果有的話。
4. 刪除HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Ora開頭的登錄檔。
5. 重開機。
6. 刪除C:\Oracle (ORACLE BASE目錄)。
7. 刪除C:\Program Files\Oracle目錄,如果windows是64位元,需刪除C:\Program Files (x86)\Oracle目錄。
8. 刪除在C:\ProgramData\Microsoft\Windows\Start Menu\Programs\目錄下與Oracle相關的子目錄。
9. 刪除C:\temp目錄下的所有檔案->再清空資源回收桶(與Oracle相關檔案)->結束。
參考資料:
http://www.oracle-base.com/articles/misc/manual-oracle-uninstall.php
1. 使用Oracle Universal Installer (OUI)移除Oracle全部安裝程式。
2. 開始->執行regedit.exe->刪除HKEY_LOCAL_MACHINE/SOFTWARE/Oracle登錄檔。
3. 如果windows是64位元,需再刪HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Oracle登錄檔,如果有的話。
4. 刪除HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Ora開頭的登錄檔。
5. 重開機。
6. 刪除C:\Oracle (ORACLE BASE目錄)。
7. 刪除C:\Program Files\Oracle目錄,如果windows是64位元,需刪除C:\Program Files (x86)\Oracle目錄。
8. 刪除在C:\ProgramData\Microsoft\Windows\Start Menu\Programs\目錄下與Oracle相關的子目錄。
9. 刪除C:\temp目錄下的所有檔案->再清空資源回收桶(與Oracle相關檔案)->結束。
參考資料:
http://www.oracle-base.com/articles/misc/manual-oracle-uninstall.php
2014年4月28日 星期一
[Oracle] PL/SQL Developer無法載入oci.dll (Could not load oci.dll)的解決辦法
說明:安裝Oracle Client 64 bits版本,使用PL/SQL Developer設定Oracle Home與OCI library後,會出現Could not load oci.dll、OCIDLL forced to oci.dll、LoadLibrary(oci.dll) returned 0的錯誤訊息,這是因為PL/SQL Developer是32 bits的應用程式,無法載入64 bits的oci.dll檔。
找到兩種解法:
1. Oracle官網(http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html)下載Instant Client Downloads for Microsoft Windows (32-bit) -> 解壓縮到某路徑 -> 將PL/SQL Developer(程式->Tools->Preferences)的Oracle Home設為此路徑 -> OCI library設為路徑\oci.dll -> 至系統內容內的環境變數新增一筆TNS_ADMIN = Oracle Client 64 bits放tnsnames.ora的路徑(例: D:\app\xxx\product\11.2.0\client_1\network\admin) -> 再打開PL/SQL Developer即可。
2. 直接安裝Oracle Client 32 bits版本,可與64 bits共存,測試過也可以。
參考資料:
http://www.databaseskill.com/488915/
http://www.oracle.com/technetwork/topics/winsoft-085727.html
http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7/
http://daniel-tu.iteye.com/blog/1276589
找到兩種解法:
1. Oracle官網(http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html)下載Instant Client Downloads for Microsoft Windows (32-bit) -> 解壓縮到某路徑 -> 將PL/SQL Developer(程式->Tools->Preferences)的Oracle Home設為此路徑 -> OCI library設為路徑\oci.dll -> 至系統內容內的環境變數新增一筆TNS_ADMIN = Oracle Client 64 bits放tnsnames.ora的路徑(例: D:\app\xxx\product\11.2.0\client_1\network\admin) -> 再打開PL/SQL Developer即可。
2. 直接安裝Oracle Client 32 bits版本,可與64 bits共存,測試過也可以。
參考資料:
http://www.databaseskill.com/488915/
http://www.oracle.com/technetwork/topics/winsoft-085727.html
http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7/
http://daniel-tu.iteye.com/blog/1276589
訂閱:
文章 (Atom)