ASP.NET中常用的三十三种代码第1/7页

所属分类: 网络编程 / ASP.NET 阅读数: 1171
收藏 0 赞 0 分享
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 + "')"); 

6.表格超连接列传递参数
<asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id=' 
 <%# DataBinder.Eval(Container.DataItem, "数据字段1")%>' & name='<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>' /> 
7.表格点击改变颜色
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='';"); 

更多精彩内容其他人还在看

.NET Core源码解析配置文件及依赖注入

这篇文章我们设计了一些复杂的概念,因为要对ASP.NET Core的启动及运行原理、配置文件的加载过程进行分析,依赖注入,控制反转等概念的讲解等
收藏 0 赞 0 分享

.NET Corek中Git的常用命令及实战演练

这篇文章将通过故事的形式从Git的历史谈起,并讲述Git的强大之处。然后通过实战演练教你如何在Github以及码云上托管我们的代码并进行代码的版本控制
收藏 0 赞 0 分享

Asp.Net Core WebAPI使用Swagger时API隐藏和分组详解

这篇文章主要给大家介绍了关于Asp.Net Core WebAPI使用Swagger时API隐藏和分组的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Asp.Net Core具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享

如何利用FluentMigrator实现数据库迁移

这篇文章主要给大家介绍了关于如何利用FluentMigrator实现数据库迁移的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享

ASP.NET Core利用Jaeger实现分布式追踪详解

这篇文章主要给大家介绍了关于ASP.NET Core利用Jaeger实现分布式追踪的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用ASP.NET Core具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享

浅谈从ASP.NET Core2.2到3.0你可能会遇到这些问题

这篇文章主要介绍了ASP.NET Core2.2到3.0可能会遇到的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

详解.net core webapi 前后端开发分离后的配置和部署

这篇文章主要介绍了.net core webapi 前后端开发分离后的配置和部署,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

详解ASP.Net Core 中如何借助CSRedis实现一个安全高效的分布式锁

这篇文章主要介绍了ASP.Net Core 中如何借助CSRedis实现一个安全高效的分布式锁,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

.net 4.5部署到docker容器的完整步骤

这篇文章主要给大家介绍了关于.net 4.5部署到docker容器的完整步骤,文中通过示例代码介绍的非常详细,对大家学习或者使用.net4.5具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享

.net core并发下线程安全问题详解

这篇文章主要给大家介绍了关于.net core并发下线程安全问题的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用.net core具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享
查看更多