资源描述
1.网址:
对于Asp.Net.我们在TextBox1中输入内容后,按下enter键后,就执行Button1的click方法。那么在page_load事件方法中写。
TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13)
|| (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return
false;}} else {return true}; ");
SQL DESC 是descend 降序意思 asc 是ascend 升序的意思
OnClientClick="return confirm('是否要删除这条记录?');"
用来判断我们选中的一个标题头时显示的“+”或“-”的图片不同:
function menu(op) {
/*for (i = 1; i < 13; i++) {
if (op == i) {
var show = document.getElementById(op.toString()).style.backgroundColor;
if (show != "#CCCCCC") {
document.getElementById(op.toString()).style.backgroundColor = "#CCCCCC";
}
} else {
document.getElementById(i.toString()).style.backgroundColor = "";
}
}*/
// 判断的是我们点击的层是显示还是隐藏
if(document.getElementById("m"+op.toString()).style.display == "block") {
document.getElementById("m"+op.toString()).style.display="none";
//用来判断我们选中的一个标题头时显示的“+”或“-”的图片不同:
document.getElementById(op.toString()).style.backgroundImage = "url(Images/plus.gif)";
}
else
{
document.getElementById("m"+op.toString()).style.display="block";
document.getElementById(op.toString()).style.backgroundImage = "url(Images/minus.gif)";
}
/*document.getElementById(op.toString()).style.backgroundColor = "#CCCCCC";*/
}
例如红框点击的:
在使用iframe框架的时候:
使用onload="javascript:this.style.height=(this.name?window.frames[this.name] : this.contentWindow).document.body.scrollHeight + 'px'"可以将我们框架中的内容完全的显示到框架中,特别是高度会和我们内容的高度一样高。还要设置iframe框架的CSS样式的高度为100%就可以了
6.在ASP.NET中使用Web测试和负载测试
2009-08-07 14:55
最近在学习ASP.NET的Web Service和Ajax,把我学习中的笔记要点发布出来,和大家共享,供新手学习。如有错误之处,请大家指出,以便我们共同进步!!
负载测试的几种测试类型
冒烟测试:确定在短时间内负载较小时应用程序如何执行
压力测试:确定在较长时间内负载较大时应用程序是否能成功运行
性能测试:确定应用程序的响应能力
容量计划测试:确定在各种容量下应用程序如何执行
Web测试一般步骤:
1.添加Web测试----
2.编辑和运行Web测试---
3.分析Web测试结果---
负载测试:
1.创建负载测试---可以添加想要测试的任何Web测试或单元测试,可以把多个Web测试放在一起进行负载测试
2.运行负载测试---模拟我们的网站在一段时间内,多个用户同时访问的情况下网站的响应情况
3.分析负载测试结果---通过测试结果,我们可以得出模拟多用户同时访问下网站的各项指标情况。
测试结果中:
User Load:表示用户负载
Requests/Sec:请求/秒,表示吞吐量,即负载测试运行期间每秒的请求数
Avg.Response Time:平均响应时间,单位是秒。
ASP.NET中 PagedDataSource类的分页
2009-07-02 22:05
分页类PagedDataSource封装了数据绑定控件与分页相关的属性,因此使用更方便
常用属性:
CurrentPageIndex 当前页
PageCount 总页数
Count 总记录数
PageSize 每页记录数
DataSource 数据源
AllowPaging 控件是否实现自动分页功能
只要将数据源和当前的页数赋值给PagedDataSource类的实例对象,其他属性(总记录数和总页数)可以自动计算得出
这是一个实例:
Code:
1. //编写绑定的方法
2. private void Databind(){
3. PagedDataSource pdsBooks= new PagedDataSource();
4. //对PagedDataSource 对象的相关属性赋值
5. pdsBooks.DataSource = BookManager.GetBooks(Convert.ToInt32(ViewState["typeid"]), (string)ViewState["Order"]);
6. pdsBooks.AllowPaging = true;
7. pdsBooks.PageSize = 4;
8. pdsBooks.CurrentPageIndex = Pager;
9. lblCurrentPage.Text = "第 " + (pdsBooks.CurrentPageIndex + 1).ToString() + " 页 共 " + pdsBooks.PageCount.ToString()+" 页";
10. //把PagedDataSource 对象赋给DataList控件
11. dlBooks.DataSource = pdsBooks;
12. dlBooks.DataBind();
13. }
网址:
打开一个窗体后自动关闭当前网页可行办法
Response.Write("<script Language=JavaScript>");
Response.Write(" window.open('index.aspx', '111', 'width=1024,height=768,top=0,left=0,toolbar=no,status=no,location=no,menubar=no,directories=no,scrollbars=no,resizable=no')");
Response.Write("</script>");
// 自动关闭前一个窗体
Response.Write("<script type='Text/jscript'>window.opener=null;window.close()
</script>");
是否以表单元素提交(特别在输入的文本框中如果输入的是javascript就会报错误,所以一定要将它设置)
ValidateRequest="false"
模糊查询
/// <summary>
/// 根据各种情况去得到雇员
/// </summary>
/// <param name="item">item传进来的下拉框的值</param>
/// <param name="name">name传进来的是文本框的值</param>
/// <returns>List<Employees>得到的是一个集合</returns>
public List<Employees> getEmployee(string item, string name)
{
// 声明一个泛型集合
List<Employees> list = new List<Employees>();
// 声明一个sql语句
string sql = "select * from Employee";
// 调用DBHelper类的ExecuteReader方法执行sql语句,根据不同的条件执行不同的语句
SqlDataReader reader = null;
if (item == "EmployeeId")
{
sql += " where EmployeeID like @name";
}
if (item == "FirstName")
{
sql += " where FirstName like @name";
}
if (item == "LastName")
{
sql += " where LastName like @name";
}
if (item == "MiddleName")
{
sql += " where MiddleName like @name";
}
// 调用DBHelper类的ExecuteReader方法执行sql语句
// 在文本框中输入的存在%时我们要将它替换为空格,
// 不然会在查询的时候查询全部
reader = DBHelper.ExecuteReader(sql, 0,new SqlParameter("name",name.Replace('%',' ')+"%"));
// 循环读取
while (reader.Read())
{
// 声明一个实体对象
Employees p = new Employees();
// 然后将读取到的值返回给该对象
p.EmployeeId = reader["EmployeeId"] as string;
p.FirstName = reader["FirstName"] as string;
p.LastName = reader["LastName"] as string;
p.MiddleName = reader["MiddleName"] as string;
p.Sex = reader["Sex"] as string;
p.BirthdayDate = Convert.ToDateTime(reader["BirthdayDate"]);
// 将读取到的对象添加到list集合当中
list.Add(p);
}
// 返回一个集合
return list;
}
2.对于Asp.Net.如果你对文本框有验证了,想让取消按钮没有这个验证,那么久要取消这个验证,就要把取消
按钮的属性设置为:
CausesValidation=false
分页
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
View.lblText.Visible = false;
View.GridView.PageIndex = e.NewPageIndex;
this.OnViewLoaded();
}
让CheckBox全部选中
<script language="javascript" type="text/javascript">
function choicseAll(str){
var v = document.getElementsByTagName("input");
for(var i=0;i<v.length;i++){
if(v[i].type=="checkbox"){
v[i].checked=str.checked;
}
}
}
</script>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" onclick="choicseAll(this)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbAll" runat="server" />
</ItemTemplate>
</asp:TemplateField>
删除全部事件
/// <summary>
/// 删除全部事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void btnDelete_Click(object sender, EventArgs e)
{
string sb = string.Empty;
for (int i = 0; i < View.GridView.Rows.Count;i++ )
{
CheckBox cb = View.GridView.Rows[i].FindControl("cbAll") as CheckBox;
if (cb.Checked == true)
{
sb += View.GridView.Rows[i].Cells[1].Text + ",";
}
}
if(sb.Length == 0){
HttpContext.Current.Response.Write("<script>alert('Please select the items you want to delete'),window.location='Default.aspx'</script>");
return;
}
if (sb.Length > 0)
{
sb = sb.Substring(0, sb.Length - 1);
}
// 执行删除事件得到结果集
int result = _controller.deleteEmployee(sb);
// 如果返回的结果集大于的话就删除成功,否则删除失败
if (result > 0)
{
this.OnViewLoaded();
HttpContext.Current.Response.Write("<script>alert('删除成功'),window.location='Default.aspx'</script>");
}
else
{
HttpContext.Current.Response.Write("<script>alert('删除失败'),window.location='Default.aspx'</script>");
}
}
删除雇员
/// <summary>
/// 删除雇员
/// </summary>
/// <param name="employeeId">employeeId根据主键删除对象</param>
/// <returns>int型的结果集</returns>
public int deleteEmployee(string employeeId)
{
// 声明一个结果集
int result = 0;
// 声明一个sql语句
string sql = "delete Employee where EmployeeID in (" + employeeId + ")";
// 调用DBHelper类的ExecuteCommand方法执行sql语句,然后传入参数
result = DBHelper.ExecuteCommand(sql, 0);
// 返回一个结果集
return result;
}
光棒效果
/// <summary>
/// 光棒效果
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">e</param>
public void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// 判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 得到链接按钮
LinkButton linkButton = e.Row.FindControl("LinkButton1") as LinkButton;
// 然后给链接按钮添加一个点击事件
linkButton.Attributes.Add("onclick", "return confirm('Delete Yes or No!')");
// 给每一行一个鼠标离开事件,和鼠标悬浮事件
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#A7C6E1'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
数据行事件
/// <summary>
/// 数据行的事件
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">e</param>
public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
// 得到的选中的哪一行的主键EmployeeId
View.lblText.Text = e.CommandArgument.ToString();
View.lblText.Visible = false;
// 判断如果该数据行点击的是Delete的话,就执行删除事件
if (e.CommandName == "Delete")
{
// 执行删除事件得到结果集
int result = _controller.deleteEmployee(View.lblText.Text.Trim());
// 如果返回的结果集大于的话就删除成功,否则删除失败
if (result > 0)
{
this.OnViewLoaded();
HttpContext.Current.Response.Write("<script>alert('删除成功'),window.location='Default.aspx'</script>");
}
else
{
HttpContext.Current.Response.Write("<script>alert('删除失败'),window.location='Default.aspx'</script>");
}
}
DBHelper类
/// <summary>
/// 声明一个只读静态的属性
/// </summary>
private static readonly string connString;
/// <summary>
/// 静态的默认构造函数在一加载的时候就去得到配置文件中的链接数据库
/// </summary>
static DBHelper()
{
connString = ConfigurationManager.ConnectionStrings["connString"].ToString();
}
#endregion
#region IEmployee ExecuteReader
/// <summary>
/// 执行读取数据
/// </summary>
/// <param name="sql">传入的sql语句</param>
/// <param name="type">传入的类型</param>
/// <returns>SqlDataReader 读取的结果</returns>
public static SqlDataReader ExecuteReader(string sql, int type)
{
// 声明一个连接数据库的链接类得到链接
SqlConnection connection = new SqlConnection(connString);
// 执行sql语句和链接
SqlCommand command = new SqlCommand(sql, connection);
// 如果传进来的type为1的时候执行为存储过程
if (type == 1)
{
command.CommandType = System.Data.CommandType.StoredProcedure;
}
// 链接数据库打开
connection.Open();
// 得到读取结果,并且关闭连接
SqlDataReader result = command.ExecuteReader(CommandBehavior.CloseConnection);
// 返回结果
return result;
}
#endregion
#region IEmployee ExecuteReader
/// <summary>
/// 执行读取数据
/// </summary>
/// <param name="sql">传入的sql语句</param>
/// <param name="type">传入的类型</param>
/// <param name="param">是否有参数</param>
/// <returns>SqlDataReader 读取的结果</returns>
public static SqlDataReader ExecuteReader(string sql, int type, params SqlParameter[] param)
{
// 声明一个连接数据库的链接类得到链接
SqlConnection connection = new SqlConnection(connString);
// 执行sql语句和链接
SqlCommand command = new SqlCommand(sql, connection);
// sql语句有参数时
command.Parameters.AddRange(param);
// 如果传进来的type为1的时候执行为存储过程
if (type == 1)
{
command.CommandType = System.Data.CommandType.StoredProcedure;
}
// 链接数据库打开
connection.Open();
// 得到读取结果,并且关闭连接
SqlDataReader result = command.ExecuteReader(CommandBehavior.CloseConnection);
// 返回结果
return result;
}
#endregion
#region IEmployee ExecuteCommand
/// <summary>
/// 执行增删改语句
/// </summary>
/// <param name="sql">传入的sql语句</param>
/// <param name="type">传入的类型</param>
/// <param name="param">是否有参数</param>
/// <returns>int 影响的行数</returns>
public static int ExecuteCommand(string sql, int type, params SqlParameter[] param)
{
// 声明一个连接数据库的链接类得到链接
SqlConnection connection = new SqlConnection(connString);
// 执行sql语句和链接
SqlCommand command = new SqlCommand(sql, connection);
// sql语句有参数时
command.Parameters.AddRange(param);
// 如果传进来的type为1的时候执行为存储过程
if (type == 1)
{
command.CommandType = System.Data.CommandType.StoredProcedure;
}
// 链接数据库打开
connection.Open();
// 执行增删改
int result = command.ExecuteNonQuery();
// 链接数据库关闭
connection.Close();
// 返回结果
return result;
}
/// <summary>
/// 执行增删改语句
/// </summary>
/// <param name="sql">传入的sql语句</param>
展开阅读全文