<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-1  評論-0  文章-0  trackbacks-0

    1.為按鈕添加確認對話框

    Button.Attributes.Add("onclick","return confirm('確認?')");

    Button.Attributes.Add("onclick","if(confirm('確定?')){return true;}else{return false;}")

     

    2.表格超連接列傳遞參數

    <asp:HyperLinkColumn Target="_blank" headertext="ID" DataTextField="id" NavigateUrl="aaa.aspx?id='<%# DataBinder.Eval(Container.DataItem, "數據字段1")%>'&name='<%# DataBinder.Eval(Container.DataItem, "數據字段2")%>'/>

     

    3.表格點擊改變顏色

    if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)

    {

     

    e.Item.Attributes.Add("onclick","this.style.backgroundColor='#99cc00';this.style.color='buttontext';this.style.cursor='default';");

    }

     

    4.清空Cookie

    Cookie.Expires=[DateTime];

    Response.Cookies("UserName").Expires = 0;

     

    5.Panel 橫向滾動,縱向自動擴展

    <asp:panel style="overflow-x:scroll;overflow-y:auto;"></asp:panel>

     

    6.數字格式化

    <%#Container.DataItem("price")%> 結果:500.0000格式化:500.00

    <%#Container.DataItem("price","{0:#,##0.00}")%>

    int i=123456;

    string s=i.ToString("###,###.00");

     

    7.日期格式化

    <%# DataBinder.Eval(Container.DataItem,"Date")%> 結果:2004-8-11 19:44:28 格式化:2004-8-11

    <%# DataBinder.Eval(Container.DataItem,"Date","{0:yyyy-M-d}")%>

     

    8.時間格式化

    string aa=DateTime.Now.ToString("yyyyMMdd");

    當前年月日時分秒 currentTime=System.DateTime.Now;

    當前年 int = DateTime.Now.Year;

    當前毫秒 int 毫秒= DateTime.Now.Millisecond;

     

    9.自定義分頁代碼

    public static int pageCount; //總頁面數

    public static int curPageIndex=1; //當前頁面   

    if(ccDataGrid.CurrentPageIndex<(ccDataGrid.PageCount - 1))

    {//下一頁

      ccDataGrid.CurrentPageIndex += 1;

      curPageIndex+=1;

    }

    bind(); // ccDataGrid數據綁定函數

    if(ccDataGrid.CurrentPageIndex>0)

    { //上一頁

      ccDataGrid.CurrentPageIndex += 1;

      curPageIndex-=1;

    }

    bind(); // ccDataGrid數據綁定函數

    int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()為跳轉值

    if(a<DataGrid1.PageCount)

    { //直接頁面跳轉

      this.ccDataGrid.CurrentPageIndex=a;

    }

    bind(); // ccDataGrid數據綁定函數

     

    10.變量.ToString()

    字符型轉換 轉為字符串

    12345.ToString("n"); //生成 12,345.00

    12345.ToString("C"); //生成 12,345.00

    12345.ToString("e"); //生成 1.234500e+004

    12345.ToString("f4"); //生成 12345.0000

    12345.ToString("x"); //生成 3039 (16進制)

    12345.ToString("p"); //生成 1,234,500.00%

     

    11.客戶端驗證控件

    //驗證空值

    <asp:requiredfieldvalidator id="valUsername" runat="server" controltovalidate="txtUsername" display="None" errormessage="請輸入用戶名 !!"></asp:requiredfieldvalidator>

    //驗證網址

    <asp:regularexpressionvalidator id="rev" runat="server" ErrorMessage="公司網址不合法[要有http://] " Display="None" ControlToValidate="txtCPWebsite" ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?"></asp:regularexpressionvalidator>

    //驗證郵箱

    <asp:RequiredFieldValidator id="rfv" runat="server" ControlToValidate="txtCPEmail" Display="None" ErrorMessage="請輸入電子郵箱 !!"></asp:RequiredFieldValidator>

    //驗證郵編

    <asp:regularexpressionvalidator id="rev5" runat="server" ErrorMessage="郵政編碼不合法 " Display="None" ControlToValidate="txtCPPostCode" ValidationExpression="\d{6}"></asp:regularexpressionvalidator>

    //顯示錯誤信息

    <asp:validationsummary id="vs" runat="server" ShowSummary="False" ShowMessageBox="True"></asp:validationsummary>

     

    12.DataBinding綁定表達式

    以該oil paintings網站案例來說,它的產品頁面都調用了DataBinding綁定表達式

    1) 普通的綁定表達式

    <%# DataBinder.Eval(Container.DataItem, "ContactName") %>

    2) 文本+綁定表達式

    <asp:Label id=lblDate runat="server" Text='<%# "[" + DataBinder.Eval(Container, "DataItem.NewsCreatedate") + "]" %>' ForeColor="Red"></asp:Label>

    3) 同時帶有顯示格式的綁定表達式

    <%# DataBinder.Eval(Container,"DataItem.USActiveDate","{0:yyyy-MM-dd}") %>

    4) 結合綁定表達式和模態框

    <A href='<%# ShowModalWin(Convert.ToString(DataBinder.Eval(Container.DataItem, "PictureImage")),Convert.ToString(DataBinder.Eval(Container.DataItem, "DetailID")),Convert.ToString(DataBinder.Eval(Container.DataItem, "PictureID")))%>'>

    其中:后臺代碼文件中ShowModalWin()方法的定義如下:

    protected string ShowModalWin(string PictureImage,string DetailID,string PictureID)

    {

    return " window.showModalDialog(\"Customers/ShowPictureInfo.aspx?pid="+PictureImage+"&did="+DetailID+"&id="+PictureID+"\",\"\",\"dialogHeight:320px;dialogWidth:480px;center:yes;help:no;status:no;scroll:no\");";

    }

    或者將參數提取出來單獨定義成一變量:

    const string WINDOWPARAMSTRING="dialogWidth:540px;dialogHeight:420px;help:0;status:0;resizeable:1;scroll:no";

    Page.RegisterStartupScript("functionscript","<script language='javascript'>window.showModalDialog('EditUserService.aspx?URID="+iURID+"','','"+WINDOWPARAMSTRING+"')</script>");

     

    13.html字符轉換的兩個函數

    public string Encode(string str)

    {

    str=str.Replace("&","&amp;");

    str=str.Replace("'","''");

    str=str.Replace("\"","&quot;");

    str=str.Replace(" ","&nbsp;");

    str=str.Replace("<","&lt;");

    str=str.Replace(">","&gt;");

    str=str.Replace("\n","<br>");

    return str;

    }

    public string Decode(string str)

    {

    str=str.Replace("\n","<br>");

    str=str.Replace("&gt;",">");

    str=str.Replace("&lt;","<");

    str=str.Replace("&nbsp;"," ");

    str=str.Replace("&quot;","\"");

    return str;

    }

    posted on 2012-02-24 20:57 mad fans 閱讀(83) 評論(0)  編輯  收藏
    主站蜘蛛池模板: 亚洲av丰满熟妇在线播放| 亚洲第一页在线视频| 亚洲蜜芽在线精品一区| 亚洲aⅴ天堂av天堂无码麻豆| 国产福利在线观看永久免费| 毛片免费全部播放无码| heyzo亚洲精品日韩| 亚洲欧洲日产国产综合网| 亚洲av无码专区在线电影天堂| 中出五十路免费视频| 国产va精品免费观看| 久久久久无码专区亚洲av| ASS亚洲熟妇毛茸茸PICS| 成人免费无码H在线观看不卡| 人妻视频一区二区三区免费| 亚洲色WWW成人永久网址| 亚洲国产乱码最新视频| 久草福利资源网站免费| 国产成人免费一区二区三区| 亚洲校园春色小说| 国产精品美女免费视频观看| 九九九精品成人免费视频| 国产精品亚洲片在线| 极品色天使在线婷婷天堂亚洲| 91精品国产免费网站| 浮力影院亚洲国产第一页| 亚洲欧美国产欧美色欲| 91久久青青草原线免费| 青青草原亚洲视频| 国产精品久久久久久亚洲小说| h在线观看视频免费网站| 国产亚洲综合色就色| 免费精品国自产拍在线播放| 性感美女视频免费网站午夜| 日韩亚洲AV无码一区二区不卡| 一进一出60分钟免费视频| 亚洲国产成人久久综合区| 亚洲剧场午夜在线观看| 亚洲精品第一综合99久久| 亚洲av成本人无码网站| 我们的2018在线观看免费高清|