1、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
2、 true}; "); SQL DESC 是descend 降序意思 asc 是ascend 升序的意思 OnClientClick="return confirm('是否要删除这条记录?');" 用来判断我们选中的一个标题头时显示的“+”或“-”的图片不同: function menu(op) { /*for (i = 1; i < 13; i++) { if (op == i) { var show = document.getEleme
3、ntById(op.toString()).style.backgroundColor; if (show != "#CCCCCC") { document.getElementById(op.toString()).style.backgroundColor = "#CCCCCC"; } } else {
4、 document.getElementById(i.toString()).style.backgroundColor = ""; } }*/ // 判断的是我们点击的层是显示还是隐藏 if(document.getElementById("m"+op.toString()).style.display == "block") { document.getElementById("m"+op.toString()).sty
5、le.display="none"; //用来判断我们选中的一个标题头时显示的“+”或“-”的图片不同: document.getElementById(op.toString()).style.backgroundImage = "url(Images/plus.gif)"; } else { document.getElementById("m"+op.toString()).style.display=
6、"block"; document.getElementById(op.toString()).style.backgroundImage = "url(Images/minus.gif)"; } /*document.getElementById(op.toString()).style.backgroundColor = "#CCCCCC";*/ } 例如红框点击的: 在使用iframe框架的时候: 使用o
7、nload="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,把我学习中的笔记要点发布出来,和大家共享,供新
8、手学习。如有错误之处,请大家指出,以便我们共同进步!! 负载测试的几种测试类型 冒烟测试:确定在短时间内负载较小时应用程序如何执行 压力测试:确定在较长时间内负载较大时应用程序是否能成功运行 性能测试:确定应用程序的响应能力 容量计划测试:确定在各种容量下应用程序如何执行 Web测试一般步骤: 1.添加Web测试---- 2.编辑和运行Web测试--- 3.分析Web测试结果--- 负载测试: 1.创建负载测试---可以添加想要测试的任何Web测试或单元测试,可以把多个Web测试放在一起进行负载测试 2.运行负载测试---模拟我们的网站在一段时间内,多个用户同时访问的情
9、况下网站的响应情况 3.分析负载测试结果---通过测试结果,我们可以得出模拟多用户同时访问下网站的各项指标情况。 测试结果中: User Load:表示用户负载 Requests/Sec:请求/秒,表示吞吐量,即负载测试运行期间每秒的请求数 Avg.Response Time:平均响应时间,单位是秒。 ASP.NET中 PagedDataSource类的分页 2009-07-02 22:05 分页类PagedDataSource封装了数据绑定控件与分页相关的属性,因此使用更方便 常用属性: CurrentPageIndex 当前页 PageCount
10、 总页数 Count 总记录数 PageSize 每页记录数 DataSource 数据源 AllowPaging 控件是否实现自动分页功能 只要将数据源和当前的页数赋值给PagedDataSource类的实例对象,其他属性(总记录数和总页数)可以自动计算得出 这是一个实例: Code: 1. //编写绑定的方法 2. private void Databind(){ 3. PagedDataSource pdsBooks= new PagedDataSource(); 4. //对PagedDataSource 对象的相关属性赋值
11、 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 +
12、 1).ToString() + " 页 共 " + pdsBooks.PageCount.ToString()+" 页"; 10. //把PagedDataSource 对象赋给DataList控件 11. dlBooks.DataSource = pdsBooks; 12. dlBooks.DataBind(); 13. } 网址: 打开一个窗体后自动关闭当前网页可行办法 Response.Write(""); // 自动关闭前一个窗体 Response.Write(""); 是否以表单元素提
14、交(特别在输入的文本框中如果输入的是javascript就会报错误,所以一定要将它设置)
ValidateRequest="false"
模糊查询
///
15、returns>
public List
16、法执行sql语句,根据不同的条件执行不同的语句 SqlDataReader reader = null; if (item == "EmployeeId") { sql += " where EmployeeID like @name"; } if (item == "FirstName") { sql += " where FirstName like @name";
17、 } if (item == "LastName") { sql += " where LastName like @name"; } if (item == "MiddleName") { sql += " where MiddleName like @name"; } // 调用DBHelper类的ExecuteRea
18、der方法执行sql语句 // 在文本框中输入的存在%时我们要将它替换为空格, // 不然会在查询的时候查询全部 reader = DBHelper.ExecuteReader(sql, 0,new SqlParameter("name",name.Replace('%',' ')+"%")); // 循环读取 while (reader.Read()) { // 声明一个实体对象 Employe
19、es 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"]
20、as string; p.Sex = reader["Sex"] as string; p.BirthdayDate = Convert.ToDateTime(reader["BirthdayDate"]); // 将读取到的对象添加到list集合当中 list.Add(p); } // 返回一个集合 return list; } 2.对于Asp.
21、Net.如果你对文本框有验证了,想让取消按钮没有这个验证,那么久要取消这个验证,就要把取消
按钮的属性设置为:
CausesValidation=false
分页
///
22、eEventArgs e)
{
View.lblText.Visible = false;
View.GridView.PageIndex = e.NewPageIndex;
this.OnViewLoaded();
}
让CheckBox全部选中
24、>
25、 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.
26、Checked == true) { sb += View.GridView.Rows[i].Cells[1].Text + ","; } } if(sb.Length == 0){ HttpContext.Current.Response.Write(""); return; } if (sb.Length > 0) { sb = sb.Substring(0, sb.Length - 1); } // 执行删除事件得到结果集 int result = _controller.deleteEmployee(sb); // 如果返回的结果集大于的
28、话就删除成功,否则删除失败 if (result > 0) { this.OnViewLoaded(); HttpContext.Current.Response.Write(""); } else { HttpContext.Current.R
29、esponse.Write("");
}
}
删除雇员
///
30、eteEmployee(string employeeId) { // 声明一个结果集 int result = 0; // 声明一个sql语句 string sql = "delete Employee where EmployeeID in (" + employeeId + ")"; // 调用DBHelper类的ExecuteCommand方法执行sql语句,然后传入参数 result = DBHelp
31、er.ExecuteCommand(sql, 0);
// 返回一个结果集
return result;
}
光棒效果
///
32、sender, GridViewRowEventArgs e) { // 判断是否是数据行 if (e.Row.RowType == DataControlRowType.DataRow) { // 得到链接按钮 LinkButton linkButton = e.Row.FindControl("LinkButton1") as LinkButton; // 然后给链接按钮添加一个点击事件
33、 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.Attri
34、butes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
数据行事件
///
35、 sender, GridViewCommandEventArgs e) { // 得到的选中的哪一行的主键EmployeeId View.lblText.Text = e.CommandArgument.ToString(); View.lblText.Visible = false; // 判断如果该数据行点击的是Delete的话,就执行删除事件 if (e.CommandName == "Delete") {
36、 // 执行删除事件得到结果集 int result = _controller.deleteEmployee(View.lblText.Text.Trim()); // 如果返回的结果集大于的话就删除成功,否则删除失败 if (result > 0) { this.OnViewLoaded(); HttpConte
37、xt.Current.Response.Write(""); } else { HttpContext.Current.Response.Write(""); }
38、 }
DBHelper类
///
39、ConfigurationManager.ConnectionStrings["connString"].ToString();
}
#endregion
#region IEmployee ExecuteReader
///
40、am>
///
41、mmand = new SqlCommand(sql, connection); // 如果传进来的type为1的时候执行为存储过程 if (type == 1) { command.CommandType = System.Data.CommandType.StoredProcedure; } // 链接数据库打开 connection.Open(); // 得到读取
42、结果,并且关闭连接
SqlDataReader result = command.ExecuteReader(CommandBehavior.CloseConnection);
// 返回结果
return result;
}
#endregion
#region IEmployee ExecuteReader
///
43、 /// 传入的sql语句
/// 传入的类型
/// 是否有参数
///
44、 { // 声明一个连接数据库的链接类得到链接 SqlConnection connection = new SqlConnection(connString); // 执行sql语句和链接 SqlCommand command = new SqlCommand(sql, connection); // sql语句有参数时 command.Parameters.AddRange(param); //
45、如果传进来的type为1的时候执行为存储过程 if (type == 1) { command.CommandType = System.Data.CommandType.StoredProcedure; } // 链接数据库打开 connection.Open(); // 得到读取结果,并且关闭连接 SqlDataReader result = c
46、ommand.ExecuteReader(CommandBehavior.CloseConnection);
// 返回结果
return result;
}
#endregion
#region IEmployee ExecuteCommand
///
47、
/// 传入的类型
/// 是否有参数
///
48、 connection = new SqlConnection(connString); // 执行sql语句和链接 SqlCommand command = new SqlCommand(sql, connection); // sql语句有参数时 command.Parameters.AddRange(param); // 如果传进来的type为1的时候执行为存储过程 if (type == 1)
49、{
command.CommandType = System.Data.CommandType.StoredProcedure;
}
// 链接数据库打开
connection.Open();
// 执行增删改
int result = command.ExecuteNonQuery();
// 链接数据库关闭
connection.Close();
// 返回结果
return result;
}
///
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818