asp.net判断输入文字是否是数字 (转)
方案一:
/**//// <summary>
/// 名称:IsNumberic
/// 功能:判断输入的是否是数字
/// 参数:string oText:源文本
/// 返回值: bool true:是 false:否
/// </summary>
public bool IsNumberic(string oText)
{
try
{
int var1=Convert.ToInt32 (oText);
return true;
}
catch
{
return false;
}
}
try catch方法
例:
try
{
Convert.ToInt32("123"):
Console.Write("是数字");
}
catch(Exception ex)
{
Console.Write("非数字");
}
注:如果有很多字符串要求判断,此方法需要大量的try catch 以及finally来处理后续的程序.不建议使用此方法。
改进一下:
因为可以转int 可以转Decimal
public bool IsNumberic(string oText)
{
try
{
Decimal Number = Convert.ToDecimal (oText);
return true;
}
catch
{
return false;
}
}
方案二:
//如果是纯数字还可以采用ASCII码进行判断
/// <summary>
/// 判断是否是数字
/// </summary>
/// <param name="str">字符串</param>
/// <returns>bool</returns>
public bool IsNumeric(string str)
{
if (str == null || str.Length == 0) &nbs
相关文档:
方法一:<asp:LinkButton runat="server" ID="lbtnClick" PostBackUrl='<%#"~/test.aspx?id="+Eval("id")%>'>zhang</asp:LinkButton>
方法二:<asp:LinkButton runat="server" ID="lbtnClick" PostBackUrl='<%#Eval("id","~/test.aspx?id={0}")%>'>zhang</asp"LinkButton> ......
方法1
HttpFileCollection files = HttpContext.Current.Request.Files;
//我设置的大小不超过A4纸的缩略图
int newWidth=620;
int newHeight=880;
System.Drawing.Image img = null;
for(int iFile = 0; iFile < files.C ......
本系列文章通过一个虚拟的案例——《MVC公告发布系统》的开发过程,全面展示了ASP.NET MVC的基本使用方法,同时在讨论了这个框架的基本原理。
这个文章系列的目的就是使朋友们更轻松的入门ASP.NET MVC。
这个系列会包含的内容有:ASP.NET ......
首先建立控件GridView1,注意噢
页面EnableEventValidation="false"必须的。
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="P ......
页面导出Excel时,常用的直接RenderControl的方法,如果表格中有数字,在Excel中往往格式会乱,比如前面有0,但显示出来后0都被去掉了。
因此要在绑定数字的时候,手动指定一下此列的格式,让数字以文本方式显示就行了
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
......