ASP.NET常用代码
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1.Attributes.Add("onclick","return confirm('确认?')");
button.attributes.add("onclick","if(confirm('are you sure...?')){return true;}else{return false;}")
3.删除表格选定记录
int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];
string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString()
4.删除表格记录警告
private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case ListItemType.Item :
case ListItemType.AlternatingItem :
case ListItemType.EditItem:
TableCell myTableCell;
myTableCell = e.Item.Cells[14];
LinkButton myDeleteButton ;
myDeleteButton = (LinkButton)myTableCell.Controls[0];
myDeleteButton.Attributes.Add("onclick","return confirm('您是否确定要删除这条信息');");
break;
default:
break;
}
}
5.点击表格行链接另一页
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 + "')");
}
★特别注意:【?id=】
相关文档:
1. 数据库访问性能优化
数据库的连接和关闭
访问数据库资源需要创建连接、打开连接和关闭连接几个操作。这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源。ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响。系统将用户的数据库连接放在连接池中, ......
原文地址:http://www.bengtbe.com/blog/post/2009/02/27/Using-StructureMap-with-the-ASPNET-MVC-framework.aspx
Using StructureMap with the ASP.NET MVC framework
2009-02-27 星期五 作者:bengtbe
在这里我要阐述的是怎么用.net frameword 框架下的StructureMap这个类.
在学习这个之间你需要对ASP.NE ......
1、给删除按钮添加是否确认提示:
前台方法:OnClientClick="return window.confirm('你确定要删除吗?')"
后台方法:btnDelete.Attributes.Add("onclick", "return confirm('您确定要删除吗?');");
2、DataSet中取值:
lblTitle.Text = ds.Tables[0].Rows[0]["Title"]. ......
什么是LINQ?
LINQ是语言集成查询(Language Integrated Query)的简称,是Visual Studio 2008 和.NET Framework 3.5 版中一项,突破性的创新,它在对象领域和数据领域之间架起了一座桥梁.
一个简单LINQ查询:
&n ......
错误 CS0001 编译器内部错误
错误 CS0003 内存溢出
错误 CS0004 提升为错误的警告
错误 CS0005 编译器选项后应跟正确的参数
错误 CS0006 找不到动态链接的元数据文件
错误 CS0007 .Net 环境初始化错误
错误 CS0008 从文件中读取元数据错 ......