1、DateTime 数字型
System.DateTime currentTime=new System.DateTime();
1.1 取当前年月日时分秒
currentTime=System.DateTime.Now;
1.2 取当前年
int 年=currentTime.Year;
1.3 取当前月
int 月=currentTime.Month;
1.4 取当前日
int 日=currentTime.Day;
1.5 取当前时
int 时=currentTime.Hour;
1.6 取当前分
int 分=currentTime.Minute;
1.7 取当前秒
int 秒=currentTime.Second;
1.8 取当前毫秒
int 毫秒=currentTime.Millisecond;
(变量可用中文)2、Int32.Parse(变量) Int32.Parse("常量")
字符型转换 转为32位数字型
1.清空Cookie
Cookie.Expires=[DateTime];
Response.Cookies("UserName").Expires = 0
2.Panel 横向滚动,纵向自动扩展
<asp:panel style="overflow-x:scroll;overflow-y:auto;"></asp:panel>
3.回车转换成Tab
<script language="javascript" for="document" event="onkeydown">
if(event.keyCode==13 && event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!=''&& event.srcElement.type!='textarea');
event.keyCode=9;
</script>
onkeydown="if(event.keyCode==13) event.keyCode=9"
示例:http://dotnet.aspx.cc/exam/enter2tab.aspx
4.数字格式化
【<%#Container.DataItem("price")%>的结果是500.0000,怎样格式化为500.00?】
<%#Container.DataItem("price","{0:¥#,##0.00}")%>
int i=123456;
string s=i.ToString("###,###.00");
5.日期格式化
【aspx页面内:<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date")%>
显示为: 2004-8-11 19:44:28 我要:2004-8-11 】
<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-M-d}")%>
××.ToString("yyyy-MM-dd")
6大小写转换
HttpUtility.HtmlEncode(string);
HttpUtility.HtmlDecode(string)
7.设定全局变量
Global.asax中
Application_Start()事件中
添加Application[属性名] = xxx;
就是你的全局变量
8. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
学习笔记之Iframe
1。iframe的用法
在aspx的<form></form>之间加入如下代码:
<IFRAME id="ifrm" height="100%" width="100%" frameBorder="no" scrolling="no" runat="server">
</IFRAME>
动态调用:
在cs的声明部分加入iframe的声明:
protected System.Web.UI.HtmlControls.HtmlGenericControl ifrm;
引用为
ifrm.Attributes["src"]="http://www.google.com";
2。让iframe的height自动调整以适应里面的内容,不出现滚动条。
在父页面中
<div id="div1"><iframe name=... src=... style="Z-INDEX: 2; VISIBILITY: inherit; WIDTH: 100%; HEIGHT: 100%" frameborder="0" scrolling="no"></iframe></div>
iframe中页面:
function window.onload()
{
var div = window.parent.document.getElementById('div1');
div.style.height=document.body.scrollHeight+20;
}
3。通过点击iframe中datagrid中的ImageButton,得到datagrid第一列的值,将这值传回父页。
foreach(DataGridItem CurRow in DataGrid1.Items)
{
((ImageButton)CurRow.Cells[2].Control[1]).Add("onclick","return(setValue("+((Label)CurRow.Cells[1].Control[1]).Text+"'));");
}
在aspx中加入
<script>
function setValue(txt)
{
window.parent.iframe名.all.textarea名.innerText=txt;
return false;
}
</script>
4。主页中一个treevie 点击节点以后 iframe 调用子页也是内容,子页进行修改以后点确定按钮刷新主页的treeview如何做。
子页
void Page_Load(Object sender, EventArgs e)
{
YourButton.Attributes["onclick"] = "javascript:parent.document.forms[0].submit(); return false;";
}
5。页面A.ASPX中嵌入了一个iframe,iframe的href指向B.ASPX,在B中有一个button,如何才能让点击这个button来刷新A.ASPX呢?
parent.window.location.reload("框架的url");
6。有一个home.aspx的页面,里面有两个iframe名字分别为A和B,我现在想在A的iframe页面里写一个跳转语句,可以让整个home页面都跳转而不是只是在A里面跳转,用this.Response.Redirect只是在A里面跳转.
Response.Write("<script language=javascript>window.parent.location.href='url'</script>")
7.通过ID查找控件,并调用其属性:
String _roleName = ((TextBox) e.Item.FindControl("控件ID")).Text;
如:
String _roleName = ((TextBox) e.Item.FindControl("roleName")).Text;
--------------------------------------------------------------------
<asp:Textbox id=roleName runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "RoleName") %>' cssclass="NormalTextBox" width="200">
</asp:Textbox>