ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:83.92KB ,
资源ID:9921357      下载积分:2 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9921357.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ASP实验报告四.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ASP实验报告四.docx

1、ASP实验报告四ASP.NET程序设计实验报告四实验题目:数据源控件与数据绑定控件指导老师:马浩专业班级:计算机科学与技术系1105班 姓 名:王媛(2011100529) 2014年5月24日一、实验题目 数据源的控件与数据绑定控件二、实验目的1、掌握在SQL Server 2005中创建数据的创建、备份。.2、掌握数据源控件sqldatasource的设置和使用。3、掌握常用数据绑定控件gridview、formview、listview的使用。4、掌握以上控件实现对数据库的增删改查。三、实验代码及截图实验代码:1、idviewtest.aspxports System.DataImpor

2、ts System.Data.SqlClientPartial Class _1101_gridviewtest Inherits System.Web.UI.Page Dim conn As SqlConnection Dim connstr As String = Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.L

3、oad If Not IsPostBack Then ViewState(sortorder) = id ViewState(orderdire) = asc bind() End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect(adduser.aspx) End Sub Protected Sub GridView1_RowDeleting(ByVal sender As Obj

4、ect, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim conn As New SqlConnection() conn = New SqlConnection(connstr) Dim cmd As New SqlCommand() conn.ConnectionString = Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False Dim sqlst

5、r = delete from student where id= & GridView1.DataKeys(e.RowIndex).Value.ToString() & conn.Open() cmd.Connection = conn cmd.CommandText = sqlstr cmd.ExecuteNonQuery() conn.Close() bind() End Sub Public Sub bind() Dim conn As New SqlConnection() conn = New SqlConnection(connstr) Dim sqlstr As String

6、= select * from student conn.ConnectionString = Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False Dim ds As New DataSet() conn.Open() Dim objadapter As New SqlDataAdapter(sqlstr, conn) objadapter.Fill(ds, student) Dim view As DataView = ds.Tables(student).DefaultView Dim so

7、rt As String = ViewState(sortorder).ToString & & ViewState(orderdire).ToString view.Sort = sort GridView1.DataSource = view GridView1.DataBind() conn.Close() End Sub Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridVie

8、w1.RowEditing GridView1.EditIndex = e.NewEditIndex bind() Dim drop_str As String = CType(GridView1.Rows(e.NewEditIndex).FindControl(HiddenField1), HiddenField).Value.ToString CType(GridView1.Rows(e.NewEditIndex).FindControl(DropDownList1), DropDownList).Text = drop_str End Sub Protected Sub GridView

9、1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating Dim xuehao As TextBox = GridView1.Rows(e.RowIndex).Cells(1).Controls(0) Dim name As TextBox = GridView1.Rows(e.RowIndex).Cells(2).Controls(0) Dim addr As String = CType(G

10、ridView1.Rows(e.RowIndex).Cells(3).Controls(1), DropDownList).SelectedValue.ToString Dim tel As TextBox = GridView1.Rows(e.RowIndex).Cells(4).Controls(0) Dim sqlstr As String = update student set xuehao= & xuehao.Text.Trim() & ,name= & name.Text.Trim() & ,addr= & addr.Trim() & ,tel= & tel.Text.Trim(

11、) & where id= & GridView1.DataKeys(e.RowIndex).Value.ToString() & Dim conn As New SqlConnection() conn = New SqlConnection(connstr) Dim cmd As New SqlCommand() conn.ConnectionString = Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False Dim sqlstr = delete from student where i

12、d= & GridView1.DataKeys(e.RowIndex).Value.ToString() & conn.Open() cmd.Connection = conn cmd.CommandText = sqlstr cmd.ExecuteNonQuery() conn.Close() GridView1.EditIndex = -1 bind() End Sub Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewC

13、ancelEditEventArgs) Handles GridView1.RowCancelingEdit GridView1.EditIndex = -1 bind() End Sub Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex End Su

14、b Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged bind() End Sub Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting Dim spage As

15、 String = e.SortExpression If ViewState(sortorder) = spage Then If ViewState(orderdire) = asc Then ViewState(orderdire) = desc Else ViewState(orderdire) = asc End If Else ViewState(sortorder) = e.SortExpression End If bind() End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal

16、e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate Then CType(e.Row.Cells(6).Controls(0), LinkButton).Attributes.Add(on

17、click, javascript:return confirm(你确认删除 & e.Row.Cells(2).Text & 吗?) End If End If Dim i As Integer For i = 0 To GridView1.Rows.Count If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Attributes.Add(onmouseover, c=this.style.backgroundColor;this.style.backgroundColor=#00A9FF) e.Row.Attributes.A

18、dd(onmouseout, this.style.backgroundColor=c) End If Next i End Sub Protected Sub quanxuan_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles quanxuan.CheckedChanged Dim i As Integer For i = 0 To GridView1.Rows.Count - 1 Dim cbox As CheckBox = GridView1.Rows(i).FindControl(Ch

19、eckBox1) If quanxuan.Checked Then cbox.Checked = True Else cbox.Checked = False End If Next End Sub Protected Sub delete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delete.Click conn = New SqlConnection(connstr) Dim cmd As SqlCommand Dim i As Integer For i = 0 To GridView1.Row

20、s.Count - 1 Dim cbox As CheckBox = GridView1.Rows(i).FindControl(CheckBox1) If cbox.Checked Then Dim sqlstr As String = delete from student where id= & GridView1.DataKeys(i).Value.ToString & cmd = New SqlCommand(sqlstr, conn) conn.Open() cmd.ExecuteNonQuery() conn.Close() End If Next bind() End Sub

21、Protected Sub cancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cancel.Click quanxuan.Checked = False Dim i As Integer For i = 0 To GridView1.Rows.Count - 1 Dim cbox As CheckBox = GridView1.Rows(i).FindControl(CheckBox1) cbox.Checked = False Next End Sub Protected Sub GridVie

22、w1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView1.SelectedIndexChanging Response.Redirect(xiangxi.aspx?id= & GridView1.DataKeys(e.NewSelectedIndex).Value.ToString & ) End Sub Protected Sub GridView1_SelectedIndexChanged(B

23、yVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged End SubEnd Class2、duser.aspxImports System.DataImports System.Data.SqlClientPartial Class _1101_adduser Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventAr

24、gs) Handles Button1.Click Try Dim conn As New SqlConnection() Dim cmd As New SqlCommand() conn.ConnectionString = Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False Dim sqlstr = insert into student(id,xuehao,name,addr,tel) values( & TextBox1.Text & , & TextBox2.Text & , & Te

25、xtBox3.Text & , & TextBox4.Text & , & TextBox5.Text & ) conn.Open() cmd.Connection = conn cmd.CommandText = sqlstr cmd.ExecuteNonQuery() conn.Close() Response.Redirect(gridviewtest.aspx) Catch ex As Exception Response.Write(用户为主键,不能重复出现) End Try End Sub Protected Sub Page_Load(ByVal sender As Object

26、, ByVal e As System.EventArgs) Handles Me.Load End SubEnd Class3、iangxi.aspxImports System.DataImports System.Data.SqlClientPartial Class _1101_xiangxi Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try Dim conn As New SqlConn

27、ection() Dim cmd As New SqlCommand() Dim rend As SqlDataReader conn.ConnectionString = Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False Dim sqlstr = select * from student where id= & Request(id) conn.Open() cmd.Connection = conn cmd.CommandText = sqlstr rend = cmd.ExecuteR

28、eader() rend.Read() Label1.Text = 学号: & rend.Item(xuehao) & Label1.Text += 姓名: & rend.Item(name) & Label1.Text += 家庭地址:& rend.Item(addr) & Label1.Text += 电话:& rend.Item(tel) & conn.Close() Catch ex As Exception Response.Write(用户信息查询败) End Try End SubEnd Class截图:五、 实验总结通过本次实验,我掌握了在SQL Server 2005中创建数据的创建、备份;.掌握了数据源控件sqldatasource的设置和使用;掌握了常用数据绑定控件gridview、formview、listview的使用;以及以上控件实现对数据库的增删改查。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1