Partial Class User
Inherits System.Web.UI.Page
Private sds As SqlDataSource = New SqlDataSource()
Public Sub New()
Me.sds.ProviderName = "System.Data.Odbc"
Me.sds.ConnectionString = "Dsn=mydata"
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.Cookies("username") Is Nothing Or Request.Cookies("userpass") Is Nothing Then
Response.Redirect("~/Default.aspx")
End If
Me.sds.SelectCommand = "select count(*) from t_user where username = ? and userpass = ? and a = 1"
Me.sds.SelectParameters.Add(1, Request.Cookies("username").Value)
Me.sds.SelectParameters.Add(2, Request.Cookies("userpass").Value)
Dim dv As System.Data.DataView = Me.sds.Select(DataSourceSelectArguments.Empty)
If dv(0)(0) = 0 Then
Response.Redirect("~/Index.aspx")
End If
If IsPostBack Then
Return
End If
Me.bangding()
End Sub
Private Sub bangding()
Me.GridView1.AllowPaging = True
Me.GridView1.AutoGenerateDeleteButton = True
Me.GridView1.AutoGenerateEditButton = True
Me.GridView1.AutoGenerateSelectButton = True
Me.GridView1.Caption = "用户管理"
Me.GridView1.DataKeyNames = New String() {"p_user_id"}
Me.sds.SelectCommand = "select * from t_user order by username asc"
Me.GridView1.DataSource = Me.sds
Me.GridView1.DataBind()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
Me.GridView1.PageIndex = e.NewPageIndex
Me.GridView1.EditIndex = -1
Me.bangding()
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
Me.GridView1.EditIndex = -1
Me.bangding()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Me.sds.DeleteCommand = "delete from t_user where p_user_id = ?"
Me.sds.DeleteParameters.Add(1, Me.GridView1.DataKeys(e.RowIndex).Values("p_user_id").ToString())
Me.sds.Delete()
Me.GridView1.EditIndex = -1
Me.bangding()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Me.GridView1.EditIndex = e.NewEditIndex
Me.bangding()
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Me.sds.UpdateCommand = "update t_user set username = ?, userpass = ?, a = ?, b = ?, c = ?, d = ?, e = ?, f = ?, g = ?, h = ?, i = ?, j = ?, k = ?, l = ?, m = ?, n = ?, o = ?, p = ?, q = ?, r = ?, s = ?, t = ?, u = ?, v = ?, w = ?, x = ?, y = ?, z = ? where p_user_id = ?"
Me.sds.UpdateParameters.Add(1, DirectCast(Me.GridView1.Rows(e.RowIndex).Cells(1).Controls(0), TextBox).Text)
Me.sds.UpdateParameters.Add(2, DirectCast(Me.GridView1.Rows(e.RowIndex).Cells(2).Controls(0), TextBox).Text)
For i As Integer = 3 To 28
Me.sds.UpdateParameters.Add(i, DirectCast(Me.GridView1.Rows(e.RowIndex).Cells(i).Controls(0), CheckBox).Checked)
Next
Me.sds.UpdateParameters.Add(29, Me.GridView1.DataKeys(e.RowIndex).Values("p_user_id").ToString())
Me.sds.Update()
Me.GridView1.EditIndex = -1
Me.bangding()
End Sub
End Class
http://localhost:49330/WebSite/User.aspx.vb最终版
最新推荐文章于 2022-04-17 14:14:43 发布