易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET(C#)常用代码30例

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=’../


相关文档:

ASP.Net中用C#实现站点计数器用户控件

asax文件:
  <%@ Control Language="c#" AutoEventWireup="false" Codebehind="counter.ascx.cs" Inherits="JiAnWeb.counter" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
  <LINK href="css.css" rel="stylesheet">
  <FONT face="宋体">
  <TABLE id="table_coun ......

asp.net页面之间传中文是乱码的处理方法

今天在做一个无刷新判断公司名称,是否重复的时候,发现一个问题就是通过javascript传到asp.net页面的值是乱码。以前没有发现。因为 以前做测试时,都是用英文字符进行的测试。今天输入汉字后,发现有这种问题。感觉可能是编码的问题。就上网查了一下。找到一些方法,如下:
1.设置web.config文件
<system.web>
&l ......

ASP.NET中"委托"(delegate)的使用简单实例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/// <summary>
/// 声明委托
/// </summary>
/// <param name="name"></param>
public delegate void GreetPeopleDelegate(st ......

asp.net 屏蔽 只能 是数字

 //数字字符
       public static string KeepNum(string str)
       {
           char[] tmp = new char[str.Length];
           char[ ......

提高Asp.Net网站性能


不要使用不必要的Session,和ASP中一样,在不必要的时候不要使用Session 
不使用不必要的Server Control  
不使用不必要的ViewState   
不要用Exception控制程序流程
禁用VB和Jscript动态数据类型
使用存储过程完成数据访问
只读数据访问不要使用DataSet  
关闭ASP.N ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号