ASP实验报告四
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
A S P实验报告四
标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N]
实验报告四实验题目:数据源控件与数据绑定控件
指导老师:马浩
专业班级:计算机科学与技术系1105班
姓名:王媛(29)
2014年5月24日
一、实验题目
数据源的控件与数据绑定控件
二、实验目的
1、掌握在SQL Server 2005中创建数据的创建、备份。.
2、掌握数据源控件sqldatasource的设置和使用。
3、掌握常用数据绑定控件gridview、formview、listview的使用。
4、掌握以上控件实现对数据库的增删改查。
三、实验代码及截图
实验代码:
1、
ports
Imports Class_1101_gridviewtest
Inherits 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 Handles 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 Handles ("")
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As Handles
'Dim conn As New SqlConnection()
conn = New SqlConnection(connstr)
Dim cmd As New SqlCommand()
' = "Data Source=.;Initial Catalog=aspnet;Integrated Security=SSPI;Pooling=False"
Dim sqlstr = "delete from student where id='" & .() & "'" ()
= conn
= sqlstr
()
()
bind()
End Sub
Public Sub bind()
' Dim conn As New SqlConnection()
conn = New SqlConnection(connstr)
Dim sqlstr As String = "select * from student"
' = "Data Source=.;Initial Catalog=aspnet;Integrated
Security=SSPI;Pooling=False"
Dim ds As New DataSet()
()
Dim objadapter As New SqlDataAdapter(sqlstr, conn)
(ds, "student")
Dim view As DataView = ("student").DefaultView
Dim sort As String = ViewState("sortorder").ToString & " " & ViewState("orderdire").ToString
= sort
= view
()
()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As Handles
=
bind()
Dim drop_str As String = CType.FindControl("HiddenField1"), HiddenField).
CType.FindControl("DropDownList1"), DropDownList).Text = drop_str End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As Handles
Dim xuehao As TextBox = .Cells(1).Controls(0)
Dim name As TextBox = .Cells(2).Controls(0)
Dim addr As String = CType.Cells(3).Controls(1), DropDownList).
Dim tel As TextBox = .Cells(4).Controls(0)
Dim sqlstr As String = "update student set xuehao='" & & "',name='" & & "',addr='" & () & "',tel='" & & "' where id='" & .() & "'"
' Dim conn As New SqlConnection()
conn = New SqlConnection(connstr)
Dim cmd As New SqlCommand()
' = "Data Source=.;Initial Catalog=aspnet;Integrated
Security=SSPI;Pooling=False"