Partial Class ผ__บร_จาค
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub GetData()
Dim CondStr As String = ""
If txt_Search.Text <> "" Then
CondStr = " and (D_donorID like '" & txt_Search.Text & "%' OR D_donorName like '" & txt_Search.Text & "%')"
End If
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
conn.Open()
Dim da As New SqlDataAdapter("select * from Table_DataDonate where 1=1 " & CondStr, conn)
Dim ds As New DataSet()
da.Fill(ds)
conn.Close()
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex = -1
GetData()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand() 'C_roomID=@C_roomID,
cmd.CommandText = " DELETE FROM Table_DataDonate " & _
" where D_donorID=@donorID "
cmd.Parameters.Add("@donorID", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("lbl_D_donorID"), Label).Text
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
GetData()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
GetData()
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand() 'C_roomID=@C_roomID,
cmd.CommandText = " UPDATE Table_DataDonate set D_donorID=@D_donorID,D_donorName=@D_donorName,D_donorAdd=@D_donorAdd,D_donoroc=@D_donoroc,D_donorTel=@D_donorTel,D_Date=@D_Date " & _
" where D_donorID=@donorID "
'CType(GridView1.Rows(e.RowIndex).FindControl("txt_C_roomID"), TextBox).Text
cmd.Parameters.Add("@D_donorID", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("txt_D_donorID"), TextBox).Text
cmd.Parameters.Add("@D_donorName", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("txt_D_donorName"), TextBox).Text
cmd.Parameters.Add("@D_donorAdd", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("txt_D_donorAdd"), TextBox).Text
cmd.Parameters.Add("@D_donoroc", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("txt_D_donoroc"), TextBox).Text
cmd.Parameters.Add("@D_donorTel", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("txt_D_donorTel"), TextBox).Text
cmd.Parameters.Add("@D_Date", SqlDbType.DateTime).Value = CType(GridView1.Rows(e.RowIndex).FindControl("txt_D_Date"), TextBox).Text
cmd.Parameters.Add("@donorID", SqlDbType.VarChar).Value = CType(GridView1.Rows(e.RowIndex).FindControl("hf_D_donorID"), HiddenField).Value
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
GridView1.EditIndex = -1
GetData()
End Sub
End Class