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;
}
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
获得字符串实际长度(包括中文字符)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
//获得字符串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://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)