http://localhost:49330/WebSite/User.aspx.vb最终版


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值