排序的问题

fornothing 2003-07-27 11:40:44
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

编辑的时候不是我想要编辑的内容
...全文
27 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fornothing 2003-07-28
  • 打赏
  • 举报
回复
再up一次
树猫 2003-07-27
  • 打赏
  • 举报
回复
up
fornothing 2003-07-27
  • 打赏
  • 举报
回复
就是排序的时候点击它,但是触发datagrid_EditCommand的时候要刷新以下

这次刷新就把数据又变回来了

这个时候处于编辑状态的那一行已经不是我想编辑的那一行了

gasover 2003-07-27
  • 打赏
  • 举报
回复
详细的口述问题的重点和难点?
fornothing 2003-07-27
  • 打赏
  • 举报
回复
帮帮忙啊
发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2003-07-27 11:40
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。