排序的问题
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Dim Dataview1 As New System.Data.DataView()
Dim ds As New DataSet()
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Dim DropDownList1 As New System.Web.UI.WebControls.DropDownList()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim InsertStr As String
InsertStr = "select distinct emp_id,fname,lname,job_id from employee "
Dim custDA As System.Data.SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(InsertStr, SqlConnection1)
custDA.Fill(ds, "employee")
Dataview1.Table = ds.Tables("employee")
DataGrid1.DataSource = Dataview1
Dim showtime As String
showtime = Trim(DateString)
Label1.Text = showtime
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim dr As DataRow
Dim item As String = e.Item.Cells(3).Text
Dim strDel As String
Dim cmdDel As New System.Data.SqlClient.SqlCommand()
strDel = "delete from employee where emp_id='" & item & "'"
SqlConnection1.Open()
cmdDel = New SqlClient.SqlCommand(strDel, SqlConnection1)
cmdDel.ExecuteNonQuery()
'显示数据库
Dim SelectStr As String
SelectStr = "select distinct emp_id,fname,lname,job_id from employee "
Dim cmdSelect As New System.Data.SqlClient.SqlCommand()
cmdSelect = New SqlClient.SqlCommand(SelectStr, SqlConnection1)
cmdSelect.ExecuteNonQuery()
DataGrid1.EditItemIndex = -1
Dataview1.Table = ds.Tables("employee")
DataGrid1.DataSource = Dataview1
DataGrid1.DataBind()
SqlConnection1.Close()
Response.Redirect("webform1.aspx")
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
' Dim DropDownList1 As New System.Web.UI.WebControls.DropDownList()
'DropDownList1 = e.Item.Cells(6).Controls(0)
'DropDownList1.DataBind()
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
Dataview1.Sort = e.SortExpression
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim emp_id, fname, lname, job_id As String
Dim tb As TextBox
DropDownList1 = e.Item.Cells(6).FindControl("DropDownList1")
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
emp_id = Trim(tb.Text)
tb = CType(e.Item.Cells(4).Controls(0), TextBox)
fname = Trim(tb.Text)
tb = CType(e.Item.Cells(5).Controls(0), TextBox)
lname = Trim(tb.Text)
job_id = Trim(DropDownList1.SelectedItem.Text)
'更新数据库
Dim Updatestr As String
Dim cmdUpdate As New System.Data.SqlClient.SqlCommand()
Updatestr = "Update employee set fname ='" & fname & "',lname='" & _
lname & "',job_id='" & job_id & "' where emp_id ='" & emp_id & "'"
SqlConnection1.Open()
cmdUpdate = New SqlClient.SqlCommand(Updatestr, SqlConnection1)
cmdUpdate.ExecuteNonQuery()
'显示数据库
Dim SelectStr As String
SelectStr = "select distinct emp_id,fname,lname,job_id from employee "
Dim cmdSelect As New System.Data.SqlClient.SqlCommand()
cmdSelect = New SqlClient.SqlCommand(SelectStr, SqlConnection1)
cmdSelect.ExecuteNonQuery()
DataGrid1.EditItemIndex = -1
Dataview1.Table = ds.Tables("employee")
DataGrid1.DataSource = Dataview1
DataGrid1.DataBind()
SqlConnection1.Close()
Response.Redirect("webform1.aspx")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Attributes.Add("onclick", "javascript:return confirm('click me');")
'Response.Redirect("http://www.google.com")
End Sub
编辑的时候不是我想要编辑的内容