溫故而知新!翻開以前剛開始使用.net 編程時記錄的編程技巧,突然覺得時間過得太快了。此片文章部分內容爲網上收集。
1、GridView裏boundfield的語法結果註釋
數字 {0:N2} 12.36
數字 {0:N0} 13
貨幣 {0:c2} 12.36
貨幣 {0:c4} 12.3656
貨幣 "¥{0:N2}" ¥12.36
科學計數法 {0:E3} 1.23E+001
百分數 {0:P} 12.25% P and p present the same.
日期 {0:D} 2006年11月25日
日期 {0:d} 2006-11-25
日期 {0:f} 2006年11月25日 10:30
日期 {0:F} 2006年11月25日 10:30:00
日期 {0:s} 2006-11-26 10:30:00
時間 {0:T} 10:30:00
2、模板列的幾種綁定語法。
<%# Eval("T_LogDate", "{0:yyyy-MM-dd}").ToString()%>
<%# Bind("T_LogDate", "{0:yyyy-MM-dd}").ToString()%>
Text='<%#ChangeSex(DataBinder.Eval(Container,"DataItem.Sex").ToString()) %>'>
- <asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
- <ItemTemplate>
- <%#( (System.Collections.Generic.KeyValuePair<string, A>)(Container.DataItem)).Key %>
- <%#( ((System.Collections.Generic.KeyValuePair<string, A>)(Container.DataItem)).Value as A).PKID %>
- <%#( ((System.Collections.Generic.KeyValuePair<string, A>)(Container.DataItem)).Value as A).Type %>
- </ItemTemplate>
- </asp:DataList>
- <asp:TemplateField HeaderText="Review Id">
<ItemTemplate>
<asp:Label ID="labReviewId" Text='<%#(((System.Collections.Generic.Dictionary<string, object>)(Container.DataItem)))["ReviewId"] %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
3、url傳遞中文的解決方案
1).設置web.config文件。
<system.web>
......
<globalization requestEncoding="gb2312" respon_seEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312" />
......
</system.web>
2).傳遞中文之前,將要傳遞的中文參數進行編碼,在接收時再進行解碼。
>> 進行傳遞
string Name = "中文參數";
Response.Redirect("B.aspx?Name="+Server.UrlEncode(Name));
>> 進行接收
string Name = Request.QueryString["Name"];
Response.Write(Server.UrlDecode(Name));
3).如果是從 .HTML 文件向 .Aspx 文件進行傳遞中文參數的話(即不從後臺用 Redirect()方法進行 Url 轉換)。一樣要將傳遞的中文參數進行編碼,在接收時再進行解碼。
>> 進行傳遞
<script language="JavaScript">
function GoUrl()
{
var Name = "中文參數";
location.href = "B.aspx?Name="+escape(Name);
}
</script>
<body on_click="GoUrl()">
>> 進行接收
string Name = Request.QueryString["Name"];
Response.Write(Server.UrlDecode(Name));
一般來說。設置web.config文件就可以了。但是如果你用 JavaScript 調用 webservice 方法的話(往webservice裏面傳遞中文參數)。設置 web.config 文件好象無效。
javascript HTMLencode實現:
|
4、XML,Html轉義字符.
C#存取binary 數據
存
byte []box=new byte[len];
mystream.Read(box,0,(int)len);
mycmd.Parameters["@a"].Value=box;
取
byte []box=(byte [])myrd["picture"];