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

11月29日 工作总结(ASP.NET代码收藏)

2010-11-30 13:45 337 查看
11月29日工作总结:
1、 修改一个页面后,发现,没必要那么麻烦……有关SQL Server转换为Access,既然Access不支持三个以上的多表查询,可以在列表动态生成的过程中,动态添加数据……
2、 该内存不能为‘Read’的问题:
出现这个现象的原因有两方面:一是硬件,即内存方面有问题,二是软件(涉及到内存分配的问题了)
3、实现连接池的优点:当数据库操作和访问频繁的时候,减少创建连接和打开连接所耗得时间,提升数据库服务器的性能
实现连接池的缺点:数据库连接池中可能存在着多个已经连接但没有被使用,造成资源浪费。
11月30日工作总结:
1、 网站上传后,访问网站,提示错误‘Server Error In’/’Application’,不知是什么原因,看似是网站不稳定,想到会不会是数据库连接的问题,此网站数据库是Access,昨天刚做了一数据库连接池,那是SQL Server的,SQL Server支持连接池,而Access不支持,稍微做了一下改动,声明类对象时,只是简单的组织一下链接语句,在自定义的方法里实现打开、关闭数据库链接,在操作之前判断数据库连接状态,如果是打开状态,先关闭,然后再打开。
2、 申请的虚拟空间,还需要网站备案,索要企业相关信息。
3、 知道有.NET探针这一功能,但还不很了解有关他的理论。
4、 知道有一个选项卡控件-----TabControl控件,有必要可以学习了解一下。
5、 前台绑定,实现时间去秒的功能:
<%#System.DateTime.Parse(DataBinder.Eval(Container.DataItem,"begtime").ToString()).ToShortDateString()%>
6、 前台绑定,输出数据格式化,“{0:F2}”是格式,F2表示小数点后剩两位:
<%# DataBinder.Eval(Container, "DataItem.PriceMoney","{0:F2}") %>
7、 提取动态网页的内容:
Uri uri = new Uri("http://www.51aspx.com/");
WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream str = resp.GetResponseStream();
StreamReader sr = new StreamReader(str,System.Text.Encoding.Default);
string t = sr.ReadToEnd();
this.Response.Write(t.ToString());
8、 打开新的窗口,并显示参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
9、点击表格行链接另一页
private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
  //点击表格打开
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  e.Item.Attributes.Add("onclick","window.open('Default.aspx?id=" + e.Item.Cells[0].Text + "');");
}
双击表格连接到另一页
  在itemDataBind事件中
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
  string orderItemID =e.item.cells[1].Text;
  e.item.Attributes.Add("ondblclick", "location.href='../ShippedGrid.aspx?id=" + orderItemID + "'");
}
双击表格打开新一页
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
  string orderItemID =e.item.cells[1].Text;
  e.item.Attributes.Add("ondblclick", "open('../ShippedGrid.aspx?id=" + orderItemID + "')");
}
10、表格超连接列传递参数
<asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id='
  <%# DataBinder.Eval(Container.DataItem, "数据字段1")%>' & name='<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>' />
11、表格点击改变颜色
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
  e.Item.Attributes.Add("onclick","this.style.backgroundColor='#99cc00';
    this.style.color='buttontext';this.style.cursor='default';");
}
写在DataGrid的_ItemDataBound里
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#99cc00';
  this.style.color='buttontext';this.style.cursor='default';");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='';this.style.color='';");
}
12、关于日期格式
  日期格式设定
DataFormatString="{0:yyyy-MM-dd}"
  我觉得应该在itembound事件中
e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))
19.获取错误信息并到指定页面
不要使用Response.Redirect,而应该使用Server.Transfer
  e.g
// in global.asax
protected void Application_Error(Object sender, EventArgs e) {
if (Server.GetLastError() is HttpUnhandledException)
Server.Transfer("MyErrorPage.aspx");
//其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :)
}
  Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: