1. 打开新的窗口并传送参数:
ASP.NET程序中常用代码汇总(一)//传送参数:
ASP.NET程序中常用代码汇总(一)
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+ASP.NET程序中常用代码汇总(一)+"’)</script>")
ASP.NET程序中常用代码汇总(一)  
//接收参数:
ASP.NET程序中常用代码汇总(一)
string a = Request.QueryString("id");
ASP.NET程序中常用代码汇总(一)
string b = Request.QueryString("id1");
2.为按钮添加对话框
ASP.NET程序中常用代码汇总(一)Button1.Attributes.Add("onclick","return confirm(’确认?’)");
ASP.NET程序中常用代码汇总(一)button.attributes.add(
"onclick","if(confirm(’are you sureASP.NET程序中常用代码汇总(一)?’)){return true;}else{return false;}")
3.删除表格选定记录
ASP.NET程序中常用代码汇总(一)int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];
ASP.NET程序中常用代码汇总(一)
string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString()
4.删除表格记录警告
ASP.NET程序中常用代码汇总(一)private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)
5.点击表格行链接另一页
ASP.NET程序中常用代码汇总(一)private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
6.表格超连接列传递参数
ASP.NET程序中常用代码汇总(一)<asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id=’
ASP.NET程序中常用代码汇总(一) <%# DataBinder.Eval(Container.DataItem, "数据字段1")%>’ & name=’<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>’ />
7.表格点击改变颜色
ASP.NET程序中常用代码汇总(一)if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)

8.关于日期格式

ASP.NET程序中常用代码汇总(一)日期格式设定
ASP.NET程序中常用代码汇总(一)DataFormatString
="{0:yyyy-MM-dd}"
ASP.NET程序中常用代码汇总(一)  
//我觉得应该在itembound事件中
ASP.NET程序中常用代码汇总(一)
e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))
9.获取错误信息并到指定页面
ASP.NET程序中常用代码汇总(一)//不要使用Response.Redirect,而应该使用Server.Transfer
ASP.NET程序中常用代码汇总(一)
  e.g
ASP.NET程序中常用代码汇总(一)
// in global.asax
Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理 
10.清空Cookie
ASP.NET程序中常用代码汇总(一)Cookie.Expires=[DateTime];
ASP.NET程序中常用代码汇总(一)Response.Cookies(
"UserName").Expires = 0
ASP.NET程序中常用代码汇总(一)
web窗体状态栏内类似跑马等效果的实现
ASP.NET程序中常用代码汇总(一)第一步:定义一个javascript代码段 
ASP.NET程序中常用代码汇总(一)
ASP.NET程序中常用代码汇总(一)遍历获取ASP.NET页面控件的名称及值 
ASP.NET程序中常用代码汇总(一)如果直接用Page.Control 获取的到只是最顶层的页面元素,而真正的拖拉放上去的文本框或Label之类的控件,还隐藏在这些顶层页面元素的里面,所以需要再次遍历。
ASP.NET程序中常用代码汇总(一)函数及使用方法如下,结果保存在这里选择了HashTable的方式。
ASP.NET程序中常用代码汇总(一)
ASP.NET程序中常用代码汇总(一)
protected void Page_Load(object sender, EventArgs e)
    }

相关文章:

  • 2021-10-30
  • 2021-10-21
  • 2022-01-10
  • 2022-02-26
猜你喜欢
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案