隨筆-1  評(píng)論-0  文章-0  trackbacks-0

          1.為按鈕添加確認(rèn)對(duì)話框

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

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

           

          2.表格超連接列傳遞參數(shù)

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

           

          3.表格點(diǎn)擊改變顏色

          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 橫向滾動(dòng),縱向自動(dòng)擴(kuò)展

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

           

          6.數(shù)字格式化

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

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

          int i=123456;

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

           

          7.日期格式化

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

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

           

          8.時(shí)間格式化

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

          當(dāng)前年月日時(shí)分秒 currentTime=System.DateTime.Now;

          當(dāng)前年 int = DateTime.Now.Year;

          當(dāng)前毫秒 int 毫秒= DateTime.Now.Millisecond;

           

          9.自定義分頁(yè)代碼

          public static int pageCount; //總頁(yè)面數(shù)

          public static int curPageIndex=1; //當(dāng)前頁(yè)面   

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

          {//下一頁(yè)

            ccDataGrid.CurrentPageIndex += 1;

            curPageIndex+=1;

          }

          bind(); // ccDataGrid數(shù)據(jù)綁定函數(shù)

          if(ccDataGrid.CurrentPageIndex>0)

          { //上一頁(yè)

            ccDataGrid.CurrentPageIndex += 1;

            curPageIndex-=1;

          }

          bind(); // ccDataGrid數(shù)據(jù)綁定函數(shù)

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

          if(a<DataGrid1.PageCount)

          { //直接頁(yè)面跳轉(zhuǎn)

            this.ccDataGrid.CurrentPageIndex=a;

          }

          bind(); // ccDataGrid數(shù)據(jù)綁定函數(shù)

           

          10.變量.ToString()

          字符型轉(zhuǎn)換 轉(zhuǎn)為字符串

          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進(jìn)制)

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

           

          11.客戶(hù)端驗(yàn)證控件

          //驗(yàn)證空值

          <asp:requiredfieldvalidator id="valUsername" runat="server" controltovalidate="txtUsername" display="None" errormessage="請(qǐng)輸入用戶(hù)名 !!"></asp:requiredfieldvalidator>

          //驗(yàn)證網(wǎng)址

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

          //驗(yàn)證郵箱

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

          //驗(yàn)證郵編

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

          //顯示錯(cuò)誤信息

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

           

          12.DataBinding綁定表達(dá)式

          以該oil paintings網(wǎng)站案例來(lái)說(shuō),它的產(chǎn)品頁(yè)面都調(diào)用了DataBinding綁定表達(dá)式

          1) 普通的綁定表達(dá)式

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

          2) 文本+綁定表達(dá)式

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

          3) 同時(shí)帶有顯示格式的綁定表達(dá)式

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

          4) 結(jié)合綁定表達(dá)式和模態(tài)框

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

          其中:后臺(tái)代碼文件中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\");";

          }

          或者將參數(shù)提取出來(lái)單獨(dú)定義成一變量:

          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字符轉(zhuǎn)換的兩個(gè)函數(shù)

          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 閱讀(84) 評(píng)論(0)  編輯  收藏
          主站蜘蛛池模板: 巩义市| 和平区| 岑溪市| 普陀区| 武夷山市| 张家川| 广德县| 钟祥市| 鲁甸县| 铜山县| 牡丹江市| 清远市| 南宁市| 沅江市| 屏山县| 米脂县| 寻乌县| 连云港市| 苏州市| 宣城市| 永清县| 金秀| 汉寿县| 万安县| 吐鲁番市| 和平区| 荆门市| 视频| 南乐县| 棋牌| 应城市| 酒泉市| 克东县| 乐陵市| 庆城县| 阿克苏市| 兴和县| 青州市| 射洪县| 元阳县| 江达县|