myString = myString.Replace(System.Environment.NewLine,"replacement text")
目前分類:ASP.NET C# (136)
- May 12 Tue 2015 17:24
C# 去除斷行 System.Environment.NewLine
- May 12 Tue 2015 12:19
MasterPage引用路徑寫法
<script src="<%=ResolveClientUrl("~/js/xxx.js") %>"> <img runat="server" src="~/qq.jpg" />
- May 09 Sat 2015 16:29
c# web.config 跑less
<system.webServer>
<staticContent>
- May 07 Thu 2015 17:18
C# Remove DataTable
if (ds.Tables.CanRemove(ds.Tables["dt_論壇子類別"]))
{
- May 07 Thu 2015 10:52
C# 取得有Request參數
- May 06 Wed 2015 14:04
線上寫C#
SELECT A.name, COUNT(B.call_id)AS'outgoing call count'FROM
EmployeeTable A
LEFTJOIN(SELECT call_from_name, call_id FROM CallTable
WHERE call_type LIKE'outgoing'AND voice_mail ='0'AND/* other CallTable filters */) B
ON A.name = B.call_from_name
WHERE/* only EmployeeTable A filters */GROUPBY A.name
- May 06 Wed 2015 12:07
C# ajax 分批載入清單(不刷新頁面)
.aspx javascript
- May 05 Tue 2015 18:07
C# ajax & ashx
http://www.dotblogs.com.tw/hatelove/archive/2009/12/22/jqueryajax.aspx
http://stackoverflow.com/questions/8951810/how-to-parse-json-data-with-jquery-javascript
- Apr 27 Mon 2015 18:02
C# DataTable 亂數排序
Random rand = new Random();
DataTable result = ds.Tables[0].AsEnumerable().OrderBy(r => rand.Next()).CopyToDataTable();
- Apr 24 Fri 2015 14:37
tinymce 插入圖片配合asp.net控制項
function 圖片上傳前() { tinymce.activeEditor.execCommand('mceInsertContent', false, '#changeimagehere#'); } <asp:Button ID="按鈕_上傳圖片" runat="server" Text="上傳" OnClientClick="圖片上傳前()" class="btn btn-success" OnClick="按鈕_上傳圖片_Click" CausesValidation="true" ValidationGroup="上傳圖片" UseSubmitBehavior="false" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="※請選擇上傳圖片" ValidationGroup="上傳圖片" ControlToValidate="FileUpload2" Display="Dynamic" ></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="FileUpload2" ValidationGroup="上傳圖片" ErrorMessage="※只能上傳副檔名為 .jpg 或.gif 或.png 的檔案" ValidationExpression="^.+\.(((g|G)(i|I)(f|F))|((j|J)(p|P)(e|E)?(g|G))|((p|P)(n|N)(g|G)))$" Display="Dynamic"></asp:RegularExpressionValidator> protected void 按鈕_上傳圖片_Click(object sender, EventArgs e) { string savePath = @"uploads/"; ImageProcess.上傳圖片(FileUpload2, ref savePath, ref errCode); System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath(savePath)); int width = objImage.Width; int height = objImage.Height; string 換圖片 = "<img src=\"" + savePath + "\" width=\"" + width + "\" height=\"" + height + "\">"; commentBox.InnerText = commentBox.InnerText.Replace("#changeimagehere#", 換圖片); 檔案管理(); }
- Apr 22 Wed 2015 10:23
搜尋結果字串變色
【Javascript 方法】
if('<%= 進階搜尋關鍵字_函式名稱%>' !='') { $('.函式名稱:contains(' + '<%= 進階搜尋關鍵字_函式名稱%>' + ')', document.body).each(function () { $(this).html($(this).html().replace( new RegExp('<%= 進階搜尋關鍵字_函式名稱%>', 'g'), '<span style="color:red">' + '<%= 進階搜尋關鍵字_函式名稱%>' + '</span>' )); }); } 【c# 方法】 函式名稱 = ds.Tables[0].Rows[i]["函式名稱"].ToString(); if (關鍵字[0] != "") { 函式名稱 = Regex.Replace(函式名稱, 關鍵字[0], string.Format("慈{0}愛", "$0"), RegexOptions.IgnoreCase); } if (關鍵字[1] != "") { 函式名稱 = Regex.Replace(函式名稱, 關鍵字[1], string.Format("慈{0}愛", "$0"), RegexOptions.IgnoreCase); } if (關鍵字[2] != "") { 函式名稱 = Regex.Replace(函式名稱, 關鍵字[2], string.Format("慈{0}愛", "$0"), RegexOptions.IgnoreCase); } 函式名稱 = Regex.Replace(函式名稱, "慈", "<span style=\"color:red;\">"); 函式名稱 = Regex.Replace(函式名稱, "愛", "</span>");
- Apr 10 Fri 2015 11:03
C# 呼叫javascript function
ClientScript.RegisterClientScriptBlock(this.GetType(), "AlertMsg", "<script language=\'javascript\'>alert(\'" + msg + "\')</script>");
- Apr 10 Fri 2015 10:55
C# Convert、Parse、TryParse、(int) 區別使用
[C#][轉型](note)Convert、Parse、TryParse、(int) 區別使用
http://www.dotblogs.com.tw/mis0800/archive/2014/01/29/142508.aspx
- Apr 10 Fri 2015 10:52
C# 取字串
http://www.dotblogs.com.tw/mis0800/archive/2014/03/11/144343.aspx
String.length():取得字串長度
String.Remove(int1,int2):從int1(起始位置)開始刪除長度為int2的字串
String.Insert(int,string):在int的位置插入string
String.Substring(int):從參數開始取出剩下的字串
String.Substring(int1,int2):取出int1開始長度為int2的字串
String.IndexOf(string):傳回第一次搜尋到字串(string)的位置
String.IndexOf(string,int):傳回第一次搜尋到字串(string)的位置,開始搜尋位置為int
String.LastIndexOf(string):跟IndexOf功能類似,但從後面開始搜尋
String.LastIndexOf(string,int):跟IndexOf功能類似,但從後面開始搜尋
String.Replace(char,char):取代字元
String.ToLower():將英文轉成小寫
String.ToUpper():將英文轉成大寫
String.Trim():刪除字串前後的空白字元
String.TrimEnd():刪除字串尾部的空白字元
String.TrimStart():刪除字串開頭的空白字元
- Apr 10 Fri 2015 09:11
C# Session PageBase
App_Code資料夾下PageBase.cs
public void session_check()
{
if ((Session["username"] == null))
{
Response.Write("<script>alert('連線逾時或沒有登入權限,請重新登入');location.href='zm_login.aspx';</script>");
}
}
實際頁面引用PageBase
public partial class _zm_news : PageBase
- Mar 26 Thu 2015 09:28
c# POST Codebehind
Response.write "<form name=""myform"" id=""myform"" action=""http://xxx.xxxx.xxx/xxx"" method=""POST"" >"
Response.Write "<input type=""hidden"" id=""card_ban"" name=""card_ban"" value=""xxxxxxxx"">"
- Mar 25 Wed 2015 18:14
C# 字串分割去空白
- Mar 23 Mon 2015 16:01
C# 物件導向 OOP
http://www.codeproject.com/Articles/771455/Diving-in-OOP-Day-Polymorphism-and-Inheritance-Ear
http://www.dotblogs.com.tw/skychang/archive/2012/05/10/72114.aspx
- Mar 23 Mon 2015 12:04
c# List用法
http://hamiltonserena.blogspot.tw/2012/09/c-list_6.html
- Mar 23 Mon 2015 09:59
貓狗物件
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Random rd = new Random(); //製造50隻熊貓 List<熊貓> 熊貓家族 = new List<熊貓>(); for (int i = 1; i < 51; i++) { int height = rd.Next(170, 200); int age = rd.Next(18, 110); if ((age + height) % 2 == 0) { 熊貓家族.Add(new 熊貓() { 姓名 = "熊貓小姐" + i.ToString() + "號", 年紀 = age, 身長 = height, 性別 = "女" }); } else { 熊貓家族.Add(new 熊貓() { 姓名 = "熊貓先生" + i.ToString() + "號", 年紀 = age, 身長 = height, 性別 = "男" }); } } //製造100隻龍貓 rd = new Random(); List<龍貓> 龍貓家族 = new List<龍貓>(); for (int i = 1; i < 101; i++) { int height = rd.Next(140, 180); int age = rd.Next(18, 110); if ((age + height) % 2 == 0) { 龍貓家族.Add(new 龍貓() { 姓名 = "龍貓小姐" + i.ToString() + "號", 年紀 = age, 身長 = height, 性別 = "女" }); }else { 龍貓家族.Add(new 龍貓() { 姓名 = "龍貓先生" + i.ToString() + "號", 年紀 = age, 身長 = height, 性別 = "男" }); } } //製造10狗狗 rd = new Random(); List<狗狗> 狗狗家族 = new List<狗狗>(); for (int i = 1; i < 11; i++) { int height = rd.Next(120, 160); int age = rd.Next(18, 110); if ((age + height) % 2 == 0) { 狗狗家族.Add(new 狗狗() { 姓名 = "哈巴狗小姐" + i.ToString() + "號", 年紀 = age, 身長 = height, 性別 = "女" }); } else { 狗狗家族.Add(new 狗狗() { 姓名 = "哈巴狗先生" + i.ToString() + "號", 年紀 = age, 身長 = height, 性別 = "男" }); } } 龍貓 龍貓媽媽 = new 龍貓(); 龍貓媽媽.年紀 = 28; 龍貓媽媽.身長 = 80; 龍貓媽媽.性別 = "女"; 龍貓孩子 龍貓弟弟 = new 龍貓孩子(); 龍貓弟弟.年紀 = 8; 龍貓弟弟.身長 = 50; 龍貓弟弟.性別 = "男"; 龍貓弟弟.技能 = "抓老鼠"; 龍貓孩子 龍貓妹妹 = new 龍貓孩子(); 龍貓妹妹.年紀 = 4; 龍貓妹妹.身長 = 40; 龍貓妹妹.性別 = "女"; 龍貓妹妹.技能 = "撿毛球"; int h_140 = 0; int h_150 = 0; int h_160 = 0; int h_170 = 0; foreach(貓貓 item in 龍貓家族) { if (item.身長 >= 140 && item.身長 < 150) { h_140++; }else if (item.身長 >= 150 && item.身長 < 160) { h_150++; } else if (item.身長 >= 160 && item.身長 < 170) { h_160++; } else if (item.身長 >= 170 && item.身長 < 180) { h_170++; } } Response.Write("身長140~150的龍貓有" + h_140 + "隻
"); Response.Write("身長150~160的龍貓有" + h_150 + "隻