Partial Class ContentAreaMaintenance
Inherits System.Web.UI.Page
Dim Column_id_BanksContentArea1 As Integer = 2
Dim Column_id_Bank As Integer = 3
Dim Column_ContentArea As Integer = 4
Dim Column_SequenceNumber As Integer = 5
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Note: The gridview had a CommandField CONVERTED into a Template Field by using the GridView's GUI
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If Session("LoggedIn") <> True Then
Response.Redirect("Login.aspx")
End If
If Not Page.IsPostBack Then
LoadGridView()
End If
End Sub
Sub LoadGridView()
Dim objConn As New SqlConnection(Session("ConnString"))
Dim objCommand As New SqlCommand
Dim objDa As New SqlDataAdapter
Dim objDs As New DataSet
objCommand.CommandText = "Select * from BanksContentArea1s where id_bank = " & Session("id_Bank") & " order by SequenceNumber"
objCommand.Connection = objConn
objDa.SelectCommand = objCommand
objDa.Fill(objDs, "Content")
objConn.Close()
GridView1.DataSource = objDs.Tables("Content")
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
'Cancel the edit...
GridView1.EditIndex = -1 'set to no selection
LoadGridView()
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
'CommandName set through the GridView's GUI
If e.CommandName = "Select" Then
Response.Write("id_bankscontentarea1=" & GridView1.Rows(e.CommandArgument).Cells(Column_id_BanksContentArea1).Text)
End If
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
'Assign the CommandArgument to the "Select" Button...
If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Header Then
Dim cmdSelect As Button = DirectCast(e.Row.FindControl("cmdSelect"), Button)
If Not cmdSelect Is Nothing Then
cmdSelect.CommandArgument = e.Row.RowIndex.ToString
End If
End If
'Hide some id columns....
e.Row.Cells(Column_id_BanksContentArea1).Visible = False
e.Row.Cells(Column_id_Bank).Visible = False
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'Let's add a javascript confirmation to the delete LinkButton...
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lb As LinkButton = e.Row.Cells(0).FindControl("lbDelete")
If Not lb Is Nothing Then
lb.Attributes.Add("Onclick", "if(!confirm('Delete this record?'))return false;")
End If
End If
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
'Delete the record...
Dim id_BanksContentArea1 As Integer = GridView1.Rows(e.RowIndex).Cells(Column_id_BanksContentArea1).Text
DeleteRecord(id_BanksContentArea1)
LoadGridView()
End Sub
Sub DeleteRecord(ByVal id_BanksContentArea1)
Dim objConn As New SqlConnection(Session("ConnString"))
Dim objcommand As New SqlCommand()
objcommand = New SqlCommand("DELETE BanksContentArea1s Where id_BanksContentArea1 = " & id_BanksContentArea1, objConn)
objConn.Open()
objcommand.ExecuteNonQuery()
objConn.Close()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
'Set the NewEditIndex, then reload the gridview...
GridView1.EditIndex = e.NewEditIndex 'set to selected row
LoadGridView()
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
'Get our new values...
Dim sNewContentArea As String = CType(GridView1.Rows(e.RowIndex).Cells(Column_ContentArea).Controls(0), TextBox).Text
Dim iNewSequenceNumber As Integer = Val(CType(GridView1.Rows(e.RowIndex).Cells(Column_SequenceNumber).Controls(0), TextBox).Text & "")
Dim id_BanksContentArea1 As Integer = Val(CType(GridView1.Rows(e.RowIndex).Cells(Column_id_BanksContentArea1).Controls(0), TextBox).Text & "")
UpdateContent(sNewContentArea, iNewSequenceNumber, id_BanksContentArea1)
'Turn off editing...
GridView1.EditIndex = -1
'Reload the gridview...
LoadGridView()
End Sub
Sub UpdateContent(ByVal ContentArea, ByVal SequenceNumber, ByVal id_BanksContentArea1)
Dim objConn As New System.Data.SqlClient.SqlConnection(Session("ConnString"))
Dim objcommand As New SqlCommand
Dim QStr As String
QStr = "UPDATE BanksContentArea1s SET "
QStr = QStr & "ContentArea1 = '" & ContentArea.Replace("'", "''") & "',"
QStr = QStr & "SequenceNumber = " & SequenceNumber
QStr = QStr & " WHERE id_BanksContentArea1 = " & id_BanksContentArea1
objcommand = New SqlCommand(QStr, objConn)
objConn.Open()
objcommand.ExecuteNonQuery()
objConn.Close()
End Sub
Protected Sub lbReturn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbReturn.Click
Response.Redirect("MainMenu.aspx")
End Sub
End Class