Asp.net序中常用代码汇总(五)
生活随笔
收集整理的這篇文章主要介紹了
Asp.net序中常用代码汇总(五)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
41.判斷是否為數字
?/**////?<summary>?
?///?名稱:IsNumberic?
?///?功能:判斷輸入的是否是數字?
?///?參數:string?oText:源文本?
?///?返回值: bool?true:是 false:否?
?///?</summary>?
??
?public?bool?IsNumberic(string?oText)?
?{?
??try?
??{?
???int?var1=Convert.ToInt32?(oText);?
???return?true;?
??}?
??catch?
??{?
???return?false;?
??}?
?}?
?獲得字符串實際長度(包括中文字符)?
?//獲得字符串oString的實際長度?
?public?int?StringLength(string?oString)?
?{?
??byte[]?strArray=System.Text?.Encoding.Default?.GetBytes?(oString);?
??int?res=strArray.Length?;?
??return?res;?
?}?
42.將回車轉換為TAB
//當在有keydown事件的控件上敲回車時,變為tab?
?public?void?Tab(System.Web?.UI.WebControls?.WebControl?webcontrol)?
?{?
??webcontrol.Attributes?.Add?("onkeydown",?"if(event.keyCode==13)?event.keyCode=9");?
?}?
43.datagrid分頁中如果刪除時出現超出索引
public?void?jumppage(System.Web.UI.WebControls.DataGrid?dg)?
?{?
??int?int_PageLess;?//定義頁面跳轉的頁數?
??//如果當前頁是最后一頁?
??if(dg.CurrentPageIndex?==?dg.PageCount-1)?
??{?
???//如果就只有一頁?
???if(dg.CurrentPageIndex?==?0)?
???{?
????//刪除后頁面停在當前頁?
????dg.CurrentPageIndex?=?dg.PageCount-1;????
???}?
???else?
???{?
????//如果最后一頁只有一條記錄?
????if((dg.Items.Count?%?dg.PageSize?==?1)?||?dg.PageSize?==?1)?
????{?
?????//把最后一頁最后一條記錄刪除后,頁面應跳轉到前一頁?
?????int_PageLess?=?2;?
????}?
????else??????//如果最后一頁的記錄數大于1,那么在最后一頁刪除記錄后仍然停在當前頁?
????{?
?????int_PageLess?=?1;?
????}?
????dg.CurrentPageIndex?=?dg.PageCount?-?int_PageLess;?
???}?
??}?
?}?
?/**////?<summary>?
?///?名稱:IsNumberic?
?///?功能:判斷輸入的是否是數字?
?///?參數:string?oText:源文本?
?///?返回值: bool?true:是 false:否?
?///?</summary>?
??
?public?bool?IsNumberic(string?oText)?
?{?
??try?
??{?
???int?var1=Convert.ToInt32?(oText);?
???return?true;?
??}?
??catch?
??{?
???return?false;?
??}?
?}?
?獲得字符串實際長度(包括中文字符)?
?//獲得字符串oString的實際長度?
?public?int?StringLength(string?oString)?
?{?
??byte[]?strArray=System.Text?.Encoding.Default?.GetBytes?(oString);?
??int?res=strArray.Length?;?
??return?res;?
?}?
42.將回車轉換為TAB
//當在有keydown事件的控件上敲回車時,變為tab?
?public?void?Tab(System.Web?.UI.WebControls?.WebControl?webcontrol)?
?{?
??webcontrol.Attributes?.Add?("onkeydown",?"if(event.keyCode==13)?event.keyCode=9");?
?}?
43.datagrid分頁中如果刪除時出現超出索引
public?void?jumppage(System.Web.UI.WebControls.DataGrid?dg)?
?{?
??int?int_PageLess;?//定義頁面跳轉的頁數?
??//如果當前頁是最后一頁?
??if(dg.CurrentPageIndex?==?dg.PageCount-1)?
??{?
???//如果就只有一頁?
???if(dg.CurrentPageIndex?==?0)?
???{?
????//刪除后頁面停在當前頁?
????dg.CurrentPageIndex?=?dg.PageCount-1;????
???}?
???else?
???{?
????//如果最后一頁只有一條記錄?
????if((dg.Items.Count?%?dg.PageSize?==?1)?||?dg.PageSize?==?1)?
????{?
?????//把最后一頁最后一條記錄刪除后,頁面應跳轉到前一頁?
?????int_PageLess?=?2;?
????}?
????else??????//如果最后一頁的記錄數大于1,那么在最后一頁刪除記錄后仍然停在當前頁?
????{?
?????int_PageLess?=?1;?
????}?
????dg.CurrentPageIndex?=?dg.PageCount?-?int_PageLess;?
???}?
??}?
?}?
轉載于:https://www.cnblogs.com/dynasty/archive/2005/12/02/289305.html
總結
以上是生活随笔為你收集整理的Asp.net序中常用代码汇总(五)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 魔术家B1路由器-魔术家路由器质量如何
- 下一篇: C/C+语言struct深层探索