Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version

A Plugin for CKEditor With Dynamic Data

, 16 Dec 2010 CPOL
With JavaScript and a bit of ASP.NET, it is possible to create a plugin for CKEditor that allows users to select from items drawn from a database.
CKEditor_Plugin.zip
CKEditor_Plugin
wwwroot
App_Data
ckeditor
plugins
staff_links
scripts
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Doc As XmlDocument = GenerateData()

        Response.Buffer = True
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "text/xml"
        Response.Write(Doc.OuterXml)
        Response.End()
    End Sub
    
    Protected Function GenerateData() As XmlDocument
        Dim Doc As New XmlDocument
        Dim Root As XmlElement = Doc.CreateElement("Personnel")
        
        Doc.AppendChild(Doc.CreateXmlDeclaration("1.0", Nothing, Nothing))
        Doc.AppendChild(Root)
        
        Dim Sql As New StringBuilder
        Dim Conn As SqlConnection = Nothing
        Dim Cmd As SqlCommand = Nothing
        Dim Adapter As SqlDataAdapter = Nothing
        Dim DS As DataSet = Nothing
        
        Dim Person As XmlElement = Nothing
        Dim Node As XmlElement = Nothing
        
        Sql.Append("SELECT EmpId, FirstName, LastName ")
        Sql.Append("FROM Employees WHERE TerminatedDate IS NULL ")
        Sql.Append("ORDER BY LastName, FirstName")
        Try
            Conn = New SqlConnection(ConnectionString)
            Cmd = New SqlCommand(Sql.ToString, Conn)
            Cmd.CommandTimeout = 300
            Adapter = New SqlDataAdapter(Cmd)
            DS = New DataSet
            Adapter.Fill(DS)
            For Each DR As DataRow In DS.Tables(0).Rows
                Person = Doc.CreateElement("Person")
                Person.SetAttribute("id", DR("EmpId").ToString)
                Person.SetAttribute("firstName", DR("FirstName").ToString)
                Person.SetAttribute("lastName", DR("LastName").ToString)
                Root.AppendChild(Person)
            Next
     
        Catch ex As Exception
            Throw ex
        Finally
            If DS IsNot Nothing Then DS.Dispose()
            If Adapter IsNot Nothing Then Adapter.Dispose()
            If Cmd IsNot Nothing Then Cmd.Dispose()
            If Conn IsNot Nothing AndAlso Conn.State <> ConnectionState.Closed Then
                Conn.Close()
                Conn.Dispose()
            End If
        End Try

        Return Doc
    End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Gregory Gadow
Software Developer (Senior)
United States United States
Gregory Gadow lives in Seattle, Washington and has been writing code for almost 25 years in more than a dozen programming languages. He works for a mid-size brokerage firm and holds the Series 7 and Series 66 brokerage licenses, but much prefers working as the company's programming department doing VB6, VB.Net, ASP, HTML, XML and SQL.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411028.1 | Last Updated 16 Dec 2010
Article Copyright 2010 by Gregory Gadow
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid