您的位置:首页 > 编程语言 > ASP

asp.net 代码 注意点

2013-10-30 14:15 253 查看
1. 模糊查询时,注意要去掉空格

前台:

<input id="txtQJBH" type="text" runat="server" />


后台:

protected void btnSearch_Click(object sender, EventArgs e)
{
if (txtQJMC.Value != string.Empty)
{
where += " and applianceName like '%" + txtQJMC.Value.Trim() + "%'"; //此处注意去掉空格,否则查不到数据
}
Bind();
}


2. 在[WebMethod]中引用Session:

string userID=Convert.ToInt32(HttpContext.Current.Session["UserID"].ToString());

3. Repeater获取具体年、月,后台方法

    public string GetYear(DateTime time)
{
string str = "" ;
if (time != null )
{
str = time.Year.ToString();
}
return str;
}
public string GetMonth(DateTime time)
{
string str = "" ;
if (time!=null )
{
str = time.Month.ToString();
}
return str
}


4. 页面打印功能:

<a onclick="window.print();" style="float:right;color:Blue;cursor:pointer;" class="noprint">打印 </a>

<style type="text/css" media="print">
.noprint
{
display: none ;
}
.print
{
display: block ;
}
</style>


5. 后台对数据库bit类型的判断

object isModify = DBUility.DbHelperSQL.GetString("select rightsModify from tb_user where userName='"+ userName +"';");
if(isModify.ToString()=="False")//权限未修改过   此处注意,从数据库中读取bit类型数据判断时,要根据"True" or "False",注意大小写
{ ...... }
else
{ ...... }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: