ASP.NET中常用的代码示例

  介绍

小编给大家分享一下ASP.NET中常用的代码示例,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!

1。打开新的窗口并传送参数:,
传送参数:

response.write(“<脚本> window.open (& # 39; * . aspx ? id=? this.DropDownList1.SelectIndex +“, id1=?……+“& # 39;) “)

接收参数:

string  a =, Request.QueryString (“id");,   string  b =, Request.QueryString (“id1");

2。为按钮添加对话框

Button1.Attributes.Add (“onclick",“return 确认(& # 39;确认? & # 39;)“),,   button.attributes.add (“onclick",“如果(确认(& # 39;断开连接,你确定吗? & # 39;)){return 真实;}{return 假;}其他“)

3。删除表格选定记录

int  intEmpID =, (int) MyDataGrid.DataKeys [e.Item.ItemIndex];,   string  deleteCmd =,“DELETE 得到Employee  where  emp_id =,,, +, intEmpID.ToString ()

4。删除表格记录警告

private  void  DataGrid_ItemCreated (Object 发送方,DataGridItemEventArgs  e),   {,   开关(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 确认(& # 39;您是否确定要删除这条信息& # 39;);“),,   休息,,   默认值:,   休息,,   },   }

5。点击表格行链接另一页

private  void  grdCustomer_ItemDataBound (object ,发送方,System.Web.UI.WebControls.DataGridItemEventArgs  e),   {,//点击表格打开,   if  (e.Item.ItemType ==, ListItemType.Item  | |, e.Item.ItemType ==, ListItemType.AlternatingItem),   e.Item.Attributes.Add (“onclick"“window.open (& # 39; default . aspx ? id=? +, e.Item.Cells [0] .Text  +,“& # 39;);“),,   },   双击表格连接到另一页,   在itemDataBind事件中,   如果(e.Item.ItemType ==, ListItemType.Item  | |, e.Item.ItemType ==, ListItemType.AlternatingItem),   {,   string  OrderItemID =e.item.cells [1]。text,,   ……,   e.item.Attributes.Add (“ondblclick",,“location.href=https://www.yisu.com/zixun/' . ./ShippedGrid.aspx吗?id=" + OrderItemID + " ' ");   }      双击表格打开新一页   如果(e.Item。ItemType==ListItemType。项目| | e.Item。ItemType==ListItemType.AlternatingItem)   {   字符串OrderItemID=e.item.cells [1]。text;   …   e.item.Attributes。添加(“ondblclick”、“开放(“. ./ShippedGrid.aspx吗?id=" + OrderItemID + " ') ");   }

6。表格超连接列传递参数

& # 39;,,,name=& # 39; <% #, DataBinder.Eval (Container.DataItem,,“数据字段2“)%> & # 39;,/>

7。表格点击改变颜色

if  (e.Item.ItemType ==, ListItemType.Item  | | e.Item.ItemType ==, ListItemType.AlternatingItem),   {,   e.Item.Attributes.Add (“onclick"“this.style.backgroundColor=& # 39; # 99 cc00& # 39;,,   ,this.style.color=& # 39; buttontext& # 39;; this.style.cursor=& # 39;默认# 39;;“),,   },,   写在DataGrid的_ItemDataBound里,   if  (e.Item.ItemType ==, ListItemType.Item  | | e.Item.ItemType ==, ListItemType.AlternatingItem),   {,   e.Item.Attributes.Add (“onmouseover"“this.style.backgroundColor=& # 39; # 99 cc00& # 39;,,   this.style.color=& # 39; buttontext& # 39;; this.style.cursor=& # 39;默认# 39;;“),,   e.Item.Attributes.Add (“onmouseout"“this.style.backgroundColor=& # 39; & # 39;; this.style.color=& # 39; & # 39;;“),,   }

8。关于日期格式

日期格式设定,   DataFormatString=皗0: yyyy-MM-dd}“,   我觉得应该在itembound事件中,   e.items.cell(“你的列“]。text=DateTime.Parse (e.items.cell(“你的列“].text.ToString (“yyyy-MM-dd"))

ASP.NET中常用的代码示例