相关代码参考价值

<pre class="html" name="code">--把list<photos>对象转换成json对象;
JavaScriptSerializer jss = new JavaScriptSerializer();
string json = jss.Serialize(list);
context.Response.Write(json);

//将序列化成json格式后日期(毫秒数)转成日期格式
function ChangeDateFormat(cellval) {
    var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    return date.getFullYear() + "-" + month + "-" + currentDate;
 }

//DataTable转换成泛型对象List<Photos>;

DataTable dt = SQLHelper.GetTable(sql, param);
            List<Photos> list = new List<Photos>();
            foreach (DataRow dr in dt.Rows)
            {
                Photos p = RowToPhotos(dr);
                list.Add(p);
            }
            return list;

实现IDisposable可以使用using 省去关闭了
//查看当前的程序集地址;
Response.Write(this.GetType().Assembly.Location);

//把相对路径转换成绝对路径;
string path = context.Request.MapPath("03-post提交.html"); 
//读取静态模板
string html = File.ReadAllText(path); 

//替换字符串 就相当于给文本框赋值
html = html.Replace("@name", name); value="@name" 表示要替换的字符;

//时间格式化; 因为时间类型是可空的.用value才能换取才真正的值;
p.PTime.Value.ToString("yyyy-MM-dd hh:mm:ss")

//return true 继续执行,return false 不执行;
οnclick='return confirm(\"确认删除?\")'

//判断是否转换成功,如果成功返回pid,前提spid是string类型;
int pid;
if (int.TryParse(spid, out pid))

//解决ie中文件名字出现乱码的问题;
string s = HttpUtility.UrlEncode(url);

//js对url进行编码
t = encodeURIComponent(t);

//删除cookie
int n = context.Request.Cookies.Count;
for (int i = 0; i < n; i++)
{
      //遍历所有的cookie
      HttpCookie hc = context.Request.Cookies[i];
      //设置
      hc.Expires = DateTime.Now.AddDays(-1);
      //把这个段代码加入才会删除浏览器的cookie
      context.Response.Cookies.Add(hc);
}
//才可以使用session操作;
using System.Web.SessionState;
//继承这个接口IRequiresSessionState

//验证码Math.random(); js中生成随机数
οnclick="this.src='ValidateCode.ashx?'+Math.random()";

--分页的代码,结合row_number后面要紧跟over,别名的必须要在表中出现所以要嵌套一下;
create proc usp_PagePhotos
   @pageIndex int,   --页码
   @pageSize int,    --页容量
   @pageCount int output  --总页数
   as
   --总共多少页
   --总数据数  --要定义个变量
   declare @count int
   select @count=COUNT(*) from Photos;
   set @pageCount=CEILING((@count*1.0)/@pageSize)
   select * from (
	select *,ROW_NUMBER() over(order by PTime desc) as num from Photos)
	t
	where t.num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize
	order by PTime desc;
--测试sp
 declare @n int
 exec usp_PagePhotos 1,3,@n output
 print @n

//多个按钮共享一个事件
Button btn = sender as Button;
   switch (btn.CommandName)
     {
            case "+":
                Response.Write("加");
                break;
            case "-":
                Response.Write("减");
                break;
            case "*":
                Response.Write("乘");
                break;
            
     }
//js效果,隔行变色,高亮显示
 $(function () {
            //奇数行的效果
            $("#photos tr:not(:first):even").css("background-color", "yellow");

            //偶数行的效果
            $("#photos tr:not(:first):odd").css("background-color", "gray");


            //鼠标放上高亮显示、鼠标离开还原
            var bgColor;
            $("#photos tr:not(:first)").hover(function () {
                bgColor = $(this).css("background-color");
                $(this).css("background-color", "blue");
            }, function () {
                $(this).css("background-color",bgColor);
            });
        })
 //全选-全不选-反选
   $(function () {
            //全选
            $('#b1').click(function () {
 		$(this).get(0).checked = true;
                //$(':checkbox').val([]);
                //$(':checkbox').attr('checked', true);
            });
            //全不选
            $('#b2').click(function () {

                $(':checkbox').attr('checked', false);
            });
            //反选
            $('#b3').click(function () {

                $(':checkbox').each(function () {

                    $(this).attr('checked', !$(this).attr('checked'))
                });
            });

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值