⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultvb.aspx.vb

📁 Telerik是很大的第三方软件制造商
💻 VB
字号:

Imports System
Imports System.Data.OleDb
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports Telerik.WebControls


Namespace Telerik.EditorExamplesVBNET.Editor.Examples.Database1
   
   '/ <summary>
   '/ Summary description for DefaultCS.
   '/ </summary>
   Public Class DefaultVB
      Inherits Telerik.QuickStart.XhtmlPage
      Protected EditedNews As HtmlInputHidden
      Protected WithEvents NewsGrid As DataGrid
      Protected WithEvents NewsEditor As RadEditor
      
      
      Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
         If Not Page.IsPostBack Then
            ReadAllRecords()
         End If
      End Sub 'Page_Load
      
      
      ' Method bellow is called on SubmitClicked event - (associated with it in InitializeComponent())
      ' Important!!! The method is called AFTER Page_Load method is executed, so make sure you do not
      ' inadvertently overwrite the editor content there before you process it here!
      Public Sub NewsEditor_SubmitClicked(sender As Object, e As EventArgs) Handles NewsEditor.SubmitClicked
         
         Dim connection As OleDbConnection = CreateConnection()
         Dim command As OleDbCommand = Nothing
         
         If EditedNews.Value <> String.Empty Then
            command = New OleDbCommand("UPDATE News SET NewsDate = Now(), NewsText = @content WHERE NewsID = @nid", connection)
            command.Parameters.Add("content", NewsEditor.Html)
            command.Parameters.Add("nid", Convert.ToInt32(EditedNews.Value))
         Else
            command = New OleDbCommand("INSERT INTO News (NewsDate, NewsText) VALUES (Now(), @content)", connection)
            command.Parameters.Add("content", NewsEditor.Html)
         End If
         Try
            command.ExecuteNonQuery()
         Catch ex As Exception
         End Try
         connection.Close()
         Me.Response.Redirect(Me.Request.Url.PathAndQuery)
      End Sub 'NewsEditor_SubmitClicked
      
      
      Private Function CreateConnection() As OleDbConnection
         Dim connection As New OleDbConnection()
         connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Request.MapPath((Me.TemplateSourceDirectory + "\News.mdb")) + ";User ID=;Password=;"
         connection.Open()
         Return connection
      End Function 'CreateConnection
      
      
      Private Sub NewsGrid_ItemCommand(sender As Object, args As DataGridCommandEventArgs) Handles NewsGrid.ItemCommand
         Dim connection As OleDbConnection = CreateConnection()
         If args.CommandName = "Delete" Then
            Dim com As New OleDbCommand("DELETE FROM News WHERE NewsID = @nid", connection)
            com.Parameters.Add("nid", args.Item.Cells(0).Text)
            com.ExecuteNonQuery()
            connection.Close()
         ElseIf args.CommandName = "Edit" Then
            Dim command As New OleDbCommand("SELECT NewsText FROM News WHERE NewsID = @nid", connection)
            command.Parameters.Add("nid", args.Item.Cells(0).Text)
            Dim record As OleDbDataReader = command.ExecuteReader()
            If record.Read() Then
               NewsEditor.Html = record.GetString(0)
               EditedNews.Value = args.Item.Cells(0).Text
            Else
               NewsEditor.Html = ""
               EditedNews.Value = ""
            End If
            record.Close()
         End If
         
         ' Add code to delete row from data source.
         ReadAllRecords()
      End Sub 'NewsGrid_ItemCommand
      
      
      Private Sub ReadAllRecords()
         Dim connection As OleDbConnection = CreateConnection()
         Dim command2 As New OleDbCommand("SELECT NewsID, NewsDate, NewsText FROM News", connection)
         NewsGrid.DataSource = command2.ExecuteReader()
         NewsGrid.DataBind()
         connection.Close()
      End Sub 'ReadAllRecords
      Protected Overrides Sub OnInit(e As EventArgs)
         '
         ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
         '
         InitializeComponent()
         MyBase.OnInit(e)
      End Sub 'OnInit
      
      
      '/ <summary>
      '/ Required method for Designer support - do not modify
      '/ the contents of this method with the code editor.
      '/ </summary>
      Private Sub InitializeComponent()
      End Sub 'InitializeComponent
   End Class 'DefaultVB ' Associate event handlers with events
End Namespace 'Telerik.EditorExamplesVBNET.Editor.Examples.Database1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -