Web design and hosting, database, cloud and social media solutions that deliver business results
  • ビジネスソリューション
    • データベースサービス
      • サーバーのアップグレードと DBA サービス
      • データウェアハウス サービス
      • データ統合
      • パワーBI
    • ウェブサイトデザイン
      • Web サイトのセキュリティ
      • Web サイトの最適化
      • ロゴデザイン
      • 支払いゲートウェイ
      • テクニカルツール
    • ビジネスサービス
      • Google クラウド サービス
      • アマゾン ウェブ サービス
      • マイクロソフト アズール
    • ソーシャルメディア
    • マイクロソフトオフィス
  • 学校
    • テスト環境
    • 学習データベース
      • 基礎
      • SQL Serverデータ
      • SQLServerのメンテナンス
      • SQL Serverの日付の使用
      • SQLServerピボットの使用-ピボット解除
      • SQLServer関数の使用
      • オープンクエリを取得
      • ツール
    • ウェブデザインを学ぶ
      • Ousia コンテンツ管理システムの構築
      • ASP-NET の使用
      • CSS の使用
      • JavaScript の使用
    • クラウドと IT サービスの学習
      • タスク スケジューラ エラー 2147943645
      • OpenSSL での SSL の要求と PFX ファイルの生成の簡単な手順
    • ソーシャル メディアの使用
      • Facebookアカウントを個人用からビジネス用に変更する
      • Google レビューを依頼する
      • ソーシャル メディアの取り組みをどこに集中させるかを選択する
      • ソーシャル メディアの画像サイズ
      • メタ データを使用してソーシャル メディア画像を設定する
  • 私たちに関しては
    • ブログ
      • Google コア アップデート 2020 年 1 月
      • インターネット上のウェブサイトに関する最も厄介なこと
      • ウェブサイトの広告リーフレットのコンテンツを選択する方法
      • エントリーレベルのゲーム機の構築
      • オンライン詐欺の防止
      • ギグエコノミーのスキマー
      • ホットチリインターネット閉鎖
      • 無料のベクター グラフィックスのトップ 5 Web サイト
    • キャリア
      • 翻訳者 英日
      • 英語-トルコ語翻訳者
    • チーム
      • アイセ・ハー
      • アリ アル アミン
      • ギャビン・クレイトン
      • サイガングー
      • スーリヤ・ムッカマラ
      • スニール・クマール
      • チェスターコッパーポット
    • ポートフォリオ
عربى (AR)čeština (CS)Deutsch (DE)English (EN-US)English (EN-GB)Español (ES)فارسی (FA)Français (FR)हिंदी (HI)italiano (IT)日本語 (JA)polski (PL)Português (PT)русский (RU)Türk (TR)中国的 (ZH)

SQL ServerおよびNETでのコンテンツ管理システムの構築

SQL ServerデータベースとASP.NET Webフォームアプリケーションを使用してコンテンツ管理システムを構築する方法これはOusiaの最初のバージョンからのものです。

コンテキスト

この記事は2012年に初めて書かれました。この時期にテクノロジーはかなり進歩しましたが、誰かがそれを見つけた場合に備えてここに残しておきます。

CMSの作成に関する記事へようこそ。この記事では、SQLとHTMLの基本知識と、SQL ServerとVisual Studio 2008のコピーをインストールする必要があります。

あなたのサイトは、コンテンツを動的に追加したい段階に達しています。無料でも有料でも( ウィキペディアでのリスト )そこにはたくさんのオプションがありますが、中間の人を引き出してあなた自身のものを作るのはどうですか?

ストレート最初のステップは、あなたがこの記事を読んで、その後これをやったことがない場合は、ASPのユーザーストアに建てを追加することで、コードの中に取得してみましょう会員の紹介を 。

2番目のステップは、SQLテーブルとストアドプロシージャをデータベースに追加することです。パフォーマンス向上のため、DocumentIDフィールドは主キーに設定されています。あなたがSQLの初心者なら、以下のアイデアを研究してください。

  • 主キー
  • 外部キー
  • SQLデータ型

SQL

--Create Tables
CREATE TABLE DocumentMenu(
DocumentMenuID int IDENTITY(1,1) NOT NULL CONSTRAINT PK_DocumentMenuID PRIMARY KEY,
DocumentMenuName nvarchar(100) NULL,
DocumentMenuMulti bit NULL
)
INSERT INTO DocumentMenu(DocumentMenuName,DocumentMenuMulti) SELECT 'Home',0
INSERT INTO DocumentMenu(DocumentMenuName,DocumentMenuMulti) SELECT 'About',0
INSERT INTO DocumentMenu(DocumentMenuName,DocumentMenuMulti) SELECT 'SQL',0
INSERT INTO DocumentMenu(DocumentMenuName,DocumentMenuMulti) SELECT 'NET',0
GO
CREATE TABLE Document(
DocumentID int IDENTITY(1,1) NOT NULL CONSTRAINT PK_DocumentID PRIMARY KEY,
DocumentMenuLinkID int NULL CONSTRAINT FK_DocumentMenuLinkID FOREIGN KEY REFERENCES DocumentMenu(DocumentMenuID),
DocumentName varchar(100) NULL,
DocumentHeader varchar(100) NULL,
DocumentText varchar(max) NULL,
DocumentLastUpdated datetime NULL,
DocumentKeyWords varchar(250) NULL,
DocumentDescription varchar(250) NULL,
DocumentSubjects varchar(250) NULL
)
GO
INSERT INTO Document(DocumentMenuLinkID,DocumentName) SELECT 1,'Home'
INSERT INTO Document(DocumentMenuLinkID,DocumentName) SELECT 2,'About'
GO
--Update Documents
CREATE PROC UpdDocument(@DocumentID INT,@DocumentMenuLinkID INT,@DocumentName VARCHAR(100),@DocumentHeader VARCHAR(100),@DocumentText VARCHAR(MAX),@DocumentKeyWords VARCHAR(250),@DocumentDescription VARCHAR(250))
AS BEGIN
IF @DocumentID = 0 BEGIN
PRINT 'Insert'
INSERT INTO Document(DocumentMenuLinkID,DocumentName,DocumentHeader,DocumentText,DocumentLastUpdated,DocumentKeyWords,DocumentDescription)
SELECT @DocumentMenuLinkID,@DocumentName,@DocumentHeader,@DocumentText,GETDATE(),@DocumentKeyWords,@DocumentDescription
SELECT SCOPE_IDENTITY()
RETURN
END
IF @DocumentID <>0 BEGIN
PRINT 'Update'
UPDATE Document SET
DocumentMenuLinkID=@DocumentMenuLinkID,DocumentName=@DocumentName,DocumentHeader=@DocumentHeader,DocumentText=@DocumentText,
DocumentLastUpdated=GETDATE(),DocumentKeyWords=@DocumentKeyWords,DocumentDescription=@DocumentDescription
WHERE DocumentID=@DocumentID
END
END
GO
--Get Documents
CREATE PROC GetDocuments(@SubjString NVARCHAR(100)) AS BEGIN
DECLARE @DocumentMenuLinkID INT=(SELECT TOP 1 DocumentMenuID FROM DocumentMenu WHERE DocumentMenuName LIKE @SubjString)
SELECT 'Article: ' + DocumentName DocumentName,
REPLACE('Blog/'+DocumentSubjects+'/'+CAST(DocumentID AS VARCHAR(10)),' ','')+'/'+REPLACE(DocumentHeader,' ',' ') URL,
'Description: ' + DocumentDescription DocumentDescription,
'Keywords: ' + DocumentKeyWords DocumentKeyWords,
CONVERT(VARCHAR(10),DocumentLastUpdated,103) DocumentLastUpdated
FROM Document
INNER JOIN DocumentMenu ON DocumentMenuID=DocumentMenuLinkID
WHERE DocumentMenuLinkID=@DocumentMenuLinkID
ORDER BY DocumentLastUpdated DESC
END
GO
--Get Document
CREATE PROC GetDocument(@DocumentID INT) AS BEGIN
SELECT TOP 1 Document.*,DocumentMenuMulti
FROM Document
INNER JOIN DocumentMenu ON DocumentMenuID=DocumentMenuLinkID
WHERE DocumentID=@DocumentID
END
GO

アプリケーションのセットアップ

これはSQLコードのためのものです。次の段階では、ドキュメントの表示、編集するドキュメントのリスト、およびドキュメントの編集ページを処理するWebページを設定します。

新しいプロジェクトまたはこれを追加するプロジェクトを開きます。 Global.asax(グローバルアプリケーションクラス)をこのプロジェクトに追加し、それにルート処理を追加し、そのルートをテーブルに登録する必要があります。次のアプリケーションでは、すべてのユーザーがアクセスできる次のページがあります。

  • ホームページ
  • ページについて
  • ログインページ(別記事に記載)
  • ブログのディレクトリ(すべてのドキュメント)
  • ブログのサブディレクトリ(SQL、.NETなど)
  • ブログ記事

Web Routing Config

<connectionStrings>
  <add name="MySqlConnection"connectionString="Data Source={servername};Initial Catalog={databasename};Integrated Security=True"providerName="System.Data.SqlClient" />
<connectionStrings>
<system.web>
  <httpsRuntime requestValidationMode="2.0"/>
<system.web>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="True"/>
<system.webServer>

インポート

System.Web.Routingをインポートする必要があります。

私はそれぞれの行が何をしているかを示すために各行にコメントしました。 Web設定ファイルにSQL接続を作成する必要もあります。

私はTinyMCEを使用しています.JavaScriptエディタを使用していますので、リクエスト検証モードを変更する必要があります。ページのルーティングでは、モジュールを更新する必要があります。

LoaderVBC#

VB

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) 'This code you only need to update
  'Fires when the application is started
  RegisterRoutes(RouteTable.Routes)
End Sub
Sub RegisterRoutes(ByVal routes As RouteCollection) 'This code you will need to add
  routes.MapPageRoute("", "Home/", "~/Home.aspx", False, New RouteValueDictionary(New With {.ArticleID = "1"})) 'Manual Route ID 1 is home page
  routes.MapPageRoute("", "About/", "~/About.aspx", False, New RouteValueDictionary(New With {.ArticleID = "2"})) 'Manual Route
  routes.MapPageRoute("", "Blog/{ArticleSection}/{ArticleID}/{*pathInfo}", "~/ContentPage.aspx") 'Article route to ignore anything further than the Article ID
  routes.MapPageRoute("", "Blog/{ArticleSection}/{ArticleID}/", "~/ContentPage.aspx") 'Article route using the Article ID
  routes.MapPageRoute("", "Blog/{ArticleSection}/", "~/ContentSubj.aspx") 'Article route using the Section ID
  routes.MapPageRoute("", "Blog/{*pathInfo}", "~/ContentSubj.aspx") 'Route to take us into the index
  routes.MapPageRoute("", "DocumentManager/{DID}/", "~/ManageDocument.aspx") 'Route to take us to edit document
  routes.MapPageRoute("", "DocumentManager/", "~/ManageDocuments.aspx") 'Route to take us to the list of documents
End Sub

C#

public void Application_Start(object sender, EventArgs e) //This code you only need to update
{
  //Fires when the application is started
  RegisterRoutes(RouteTable.Routes);
}
public void RegisterRoutes(RouteCollection routes) //This code you will need to add
{
  routes.MapPageRoute("", "Home/", "~/Home.aspx", false, new RouteValueDictionary(new { ArticleID = "1" }));
  //Manual Route ID 1 is home page
  routes.MapPageRoute("", "About/", "~/About.aspx", false, new RouteValueDictionary(new { ArticleID = "2" }));
  //Manual Route
  routes.MapPageRoute("", "Blog/{ArticleSection}/{ArticleID}/{*pathInfo}", "~/ContentPage.aspx");
  //Article route to ignore anything further than the Article ID
  routes.MapPageRoute("", "Blog/{ArticleSection}/{ArticleID}/", "~/ContentPage.aspx");
  //Article route using the Article ID
  routes.MapPageRoute("", "Blog/{ArticleSection}/", "~/ContentSubj.aspx");
  //Article route using the Section ID
  routes.MapPageRoute("", "Blog/{*pathInfo}", "~/ContentSubj.aspx");
  //Route to take us into the index
  routes.MapPageRoute("", "DocumentManager/{DID}/", "~/ManageDocument.aspx");
  //Route to take us to edit document
  routes.MapPageRoute("", "DocumentManager/", "~/ManageDocuments.aspx");
  //Route to take us to the list of documents
}

ドキュメントライブラリを管理する

ここでは、すべてのドキュメントのリストとそれらを表示または編集するためのリンクがあります...

このために、ManageDocuments.aspxという新しいWebフォームを追加します

LoaderHTMLVBC#

HTML

<div>
<asp:GridView ID="MyDocs" runat="server" AutoGenerateColumns="False" Width="100%" BorderStyle="None" GridLines="None">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="EditURL"DataTextField="DocName"
            HeaderText="EditDocument" />
        <asp:BoundField DataField="DocumentHeader"HeaderText="DocumentHeader" />
    </Columns>
</asp:GridView>
</div>
<div>
<a href="DocumentManager/0/">Add New</a>
</div>

VB

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
  If User.IsInRole("SiteAdmin") Then
  'If Not IsPostBack Then
  Dim com As New SqlCommand("SELECT 'DocumentManager/'+CAST(DocumentID AS VARCHAR(10)) EditURL,DocumentName DocName,DocumentHeader,REPLACE('Blog/'+DocumentSubjects+'/'+CAST(DocumentID AS VARCHAR(10)),' ','')+'/'+DocumentName PreviewURL FROM Document", con)
  con.Open()
  Dim dr = com.ExecuteReader
  MyDocs.DataSource = dr
  MyDocs.DataBind()
  con.Close()
  'End If
  End If
End
 Sub

C#

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString);
protected void Page_Load(object sender, System.EventArgs e)
{
  if (User.IsInRole("SiteAdmin"))
  {
  //If Not IsPostBack Then
  SqlCommand com = new SqlCommand("SELECT 'DocumentManager/'+CAST(DocumentID AS VARCHAR(10)) EditURL,DocumentName DocName,DocumentHeader,REPLACE('Blog/'+DocumentSubjects+'/'+CAST(DocumentID AS VARCHAR(10)),' ','')+'/'+DocumentName PreviewURL FROM Document", con);
  con.Open();
   dynamic dr = com.ExecuteReader;
  MyDocs.DataSource = dr;
  MyDocs.DataBind();
  con.Close();
  //wwwd If
  }
}

テキストエディタ

ここで私はTiny MCEのテキストエディタを使いました。私はこれが本当にうまくいくと思っていましたが、それを使うためのいくつかのステップがあります。

まず、ManageDocument.aspxという新しいWebフォームを追加します。手動でスクリプトマネージャを追加する必要があります。

LoaderHTMLJavaScriptVBC#

HTML

<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div style="text-align: center;">
<div>Menu</div>
<div>
    <asp:DropDownList ID="PageMenu" runat="server">
    </asp:DropDownList>
    </div>
<div>Page Name</div>
<div><asp:TextBox ID="PageName" runat="server" Width="400px"></asp:TextBox></div>
<div>Header</div>
<div><asp:TextBox ID="HeaderText" runat="server" Width="99%"></asp:TextBox></div>
<div>Content</div>
<div><textarea name="content" cols="1" rows="45" style="width: 100%; margin: 0 0 0 0;" id="ContentText" runat="server"></textarea></div>
<div>Key Words</div>
<div><asp:TextBox ID="KeyWords" runat="server" Width="99%"></asp:TextBox></div>
<div>Description</div>
<div><asp:TextBox ID="Description" runat="server" Width="99%"></asp:TextBox></div>
<div><asp:Button ID="AddUpdate" runat="server" Text="Button"/></div>
</div>
</ContentTemplate>
    <triggers>
        <asp:PostBackTrigger ControlID="AddUpdate"/>
    </triggers>
</asp:UpdatePanel>

JavaScript

<script type="text/javascript" src="/tiny_mce/tiny_mce_src.js">
</script>
<script type="text/javascript">
  tinyMCE.init({
  mode: "textareas",
  theme: "advanced",
  plugins: "emotions,spellchecker,advhr,insertdatetime,preview",
  theme_advanced_buttons1: "newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
  theme_advanced_buttons2: "cut,copy,paste,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,image,|,code,preview,|,forecolor,backcolor",
  theme_advanced_buttons3: "insertdate,inserttime,|,spellchecker,advhr,,removeformat,|,sub,sup,|,charmap,emotions",
  theme_advanced_toolbar_location: "top",
  theme_advanced_toolbar_align: "left",
  theme_advanced_statusbar_location: "bottom",
  width: '100%'
  });
  function UpdateTextArea() {
  tinyMCE.triggerSave(false, true);
  }
</script>

VB

Imports System.Data.SqlClient 
'Above your class
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString)
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
  If User.IsInRole("SiteAdmin") Then
  If Not IsPostBack Then
  If Not IsNothing(Page.RouteData.Values("DID")) Then
  AddUpdate.Attributes.Add("onclick", "UpdateTextArea()")
  Dim docID As String = Page.RouteData.Values("DID").ToString
  If docID = 0 Then
  AddUpdate.Text = "Add Document"
  Else
  AddUpdate.Text = "Update Document"
  End If
  Dim com As New SqlCommand("SELECT * FROM DocumentMenu WHERE (CASE WHEN " & docID & "=0 THEN 1 ELSE DocumentMenuMulti END)=DocumentMenuMulti; " & _
  "EXEC GetDocumentByID " & docID & "", con)
  con.Open()
  Dim da = New SqlDataAdapter(com)
  Dim ds As New DataSet
  da.Fill(ds)
  'Menu
  PageMenu.DataTextField = "DocumentMenuName"
   PageMenu.DataValueField = "DocumentMenuID"
  PageMenu.DataSource = ds.Tables(0)
  PageMenu.DataBind()
  'Data
  Dim dr = ds.Tables(1).CreateDataReader
   While dr.Read()
  PageMenu.SelectedValue = dr.Item(1).ToString
  PageName.Text = dr.Item(2).ToString
  HeaderText.Text = dr.Item(3).ToString
  ContentText.InnerHtml = httpsUtility.HtmlDecode(dr.Item(4).ToString)
  KeyWords.Text = dr.Item(6).ToString
  Description.Text = dr.Item(7).ToString
  PageMenu.Enabled = CBool(dr.Item(9).ToString)
   End While
  con.Close()
  Else
  Response.Redirect("/DocumentManager")
  End If
  Else
  End If
  Else
  Response.Redirect("/Login")
  End If
  End Sub
  Private Sub AddUpdate_Click() Handles AddUpdate.Click
  If Not IsNothing(Page.RouteData.Values("DID")) Then
  Dim docID As String = Page.RouteData.Values("DID").ToString
  Dim DocumentMenuLinkID As Integer = PageMenu.SelectedValue
  Dim DocumentName As String = Replace(PageName.Text, "'", "''")
  Dim DocumentHeader As String = Replace(HeaderText.Text, "'", "''")
  Dim DocumentText As String = Replace(ContentText.InnerHtml, "'", "''")
  Dim DocumentKeyWords As String = Replace(KeyWords.Text, "'", "''")
  Dim DocumentDescription As String = Replace(Description.Text, "'", "''")
  Dim com As New SqlCommand("EXEC UpdDocument " & docID & ",'" & DocumentMenuLinkID & "','" & DocumentName & "','" & DocumentHeader & "',N'" & DocumentText & "','" & DocumentKeyWords & "','" & DocumentDescription & "'", con)
  con.Open()
  Dim a As String = com.ExecuteScalar
  con.Close()
  If docID = 0 Then
  Response.Redirect("~/DocumentManager/" + a)
  End If
  End If
  End Sub

C#

using System.Data.Sql;//Above your class

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString);
protected void Page_Load(object sender, System.EventArgs e)
{
  if (User.IsInRole("SiteAdmin"))
  {
  if (!IsPostBack)
  {
  if ((Page.RouteData.Values("DID") != null))
  {
   AddUpdate.Attributes.Add("onclick", "UpdateTextArea()");
  string docID = Page.RouteData.Values("DID").ToString;
  if (docID == 0)
  {
  AddUpdate.Text = "Add Document";
  }
  else
  {
  AddUpdate.Text = "Update Document";
  }
  SqlCommand com = new SqlCommand("SELECT * FROM DocumentMenu WHERE (CASE WHEN " + docID + "=0 THEN 1 ELSE DocumentMenuMulti END)=DocumentMenuMulti; " + "EXEC GetDocumentByID " + docID + "", con);
  con.Open();
  dynamic da = new SqlDataAdapter(com);
  DataSet ds = new DataSet();
  da.Fill(ds);
  //Menu
  PageMenu.DataTextField = "DocumentMenuName";
  PageMenu.DataValueField = "DocumentMenuID";
  PageMenu.DataSource = ds.Tables(0);
  PageMenu.DataBind();
  //Data
  dynamic dr = ds.Tables(1).CreateDataReader;
  while (dr.Read())
  {
  PageMenu.SelectedValue = dr.Item(1).ToString;
  PageName.Text = dr.Item(2).ToString;
   HeaderText.Text = dr.Item(3).ToString;
  ContentText.InnerHtml = httpsUtility.HtmlDecode(dr.Item(4).ToString);
  KeyWords.Text = dr.Item(6).ToString;
  Description.Text = dr.Item(7).ToString;
   PageMenu.Enabled = Convert.ToBoolean(dr.Item(9).ToString);
  }
  con.Close();
  }
  else
  {
  Response.Redirect("/DocumentManager");
  }
  }
  else
  {
  }
  }
  else
  {
  Response.Redirect("/Login");
  }
}
private void AddUpdate_Click()
{
  if ((Page.RouteData.Values("DID") != null))
  {
  string docID = Page.RouteData.Values("DID").ToString;
  int DocumentMenuLinkID = PageMenu.SelectedValue;
  string DocumentName = Strings.Replace(PageName.Text, "'", "''");
  string DocumentHeader = Strings.Replace(HeaderText.Text, "'", "''");
  string DocumentText = Strings.Replace(ContentText.InnerHtml, "'", "''");
  string DocumentKeyWords = Strings.Replace(KeyWords.Text, "'", "''");
  string DocumentDescription = Strings.Replace(Description.Text, "'", "''");
  SqlCommand com = new SqlCommand("EXEC UpdDocument " + docID + ",'" + DocumentMenuLinkID + "','" + DocumentName + "','" + DocumentHeader + "','" + DocumentText + "','" + DocumentKeyWords + "','" + DocumentDescription + "'", con);
  con.Open();
  string a = com.ExecuteScalar;
  con.Close();
  if (docID == 0)
  {
  Response.Redirect("~/DocumentManager/" + a);
  }
  }
}
  

ディレクトリページ

このページには、経路指定したコンテンツの件名を使用しているすべての記事が表示されます。

それが設計されている方法では、2つのセクションで同じページを使用し、必要な場所にのみフィルタを効果的に供給することができます...

新しいWebフォームを追加するContentSubj.aspx

LoaderHTMLVBC#

HTML

<div><h1><asp:Label id="HeaderLabel" runat="server" Text="PageTitle"></asp:Label></h1></div>
<div id="ContentText" runat="server"></div>
<div>
<asp:GridView id="ContentSub" runat="server" AutoGenerateColumns="False" GridLines="None"ShowHeader="False"Width="100%">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
               <div style="width: 80%; float: left;">
                   <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("HyperLink") %>' Text='<%# Eval("DocumentName") %>'></asp:HyperLink>
               </div>
               <div style="width: 19%; float: left;">
                   <asp:Label ID="Label2" runat="server" text='<%# Eval("DocumentLastUpdated") %>'></asp:Label>
               </div>
               <div style="width: 100%; float: left; clear: both;">
                   <asp:Label ID="Label1" runat="server" text='<%# Eval("DocumentDescription") %>'></asp:Label>
               </div>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
</div>

VB

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Try
  Page.Title = "gsclayton.net Technical Articles"
  Page.MetaKeywords = "gsclayton.net, Databases, Web Design, SQL, HTML, .NET, ASP, CSS, Technical Articles"
  Page.MetaDescription = "gsclayton.net Databases and Web Design, SQL, HTML, .NET, ASP, CSS, Technical Articles"
  Dim Str As String = Replace(Page.RouteData.Values("Subj").ToString, "'", "''")
  Subject.Text = "La " + Str + " Articles"
  Dim com As New SqlCommand("EXEC GetDocuments '%" & Str & "%'", con)
  con.Open()
  Dim dr = com.ExecuteReader
  MyDocs.DataSource = dr
  MyDocs.DataBind()
  dr.Close()
  con.Close()
  Catch ex As Exception
  Response.Redirect("/Blog")
  End Try
End Sub

C#

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString);
protected void Page_Load(object sender, System.EventArgs e)
{
  try
  {
  Page.Title = "gsclayton.net Technical Articles";
  Page.MetaKeywords = "gsclayton.net, Databases, Web Design, SQL, HTML, .NET, ASP, CSS, Technical Articles";
  Page.MetaDescription = "gsclayton.net Databases and Web Design, SQL, HTML, .NET, ASP, CSS, Technical Articles";
  string Str = Strings.Replace(Page.RouteData.Values("Subj").ToString, "'", "''");
  Subject.Text = "La " + Str + " Articles";
  SqlCommand com = new SqlCommand("EXEC GetDocuments '%" + Str + "%'", con);
  con.Open();
  dynamic dr = com.ExecuteReader;
  MyDocs.DataSource = dr;
  MyDocs.DataBind();
  dr.Close();
  con.Close();
  }
  catch (Exception ex)
  {
  Response.Redirect("/Blog");
  }
}

コンテンツページ

自宅やページについてカスタムコンテンツを必要としない場合は、コンテンツページを追加してページのルーティングを編集するだけです。

これらのページでは、好きなように追加してスタイルを設定することができますが、次のコードがあれば動作します。

LoaderHTMLVBC#

HTML

<h1><asp:Label ID="Subject" runat="server" Text="My QMS System"></asp:Label></h1>
<div id="MyContent" runat="server"></div>
<div id="LastUpd" runat="server" style="clear: both;"></div>

VB

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
  'If Not IsPostBack Then
If Not IsNothing(Page.RouteData.Values("ArticleID")) Then
  Dim LastUpdated As Label = Master.FindControl("LastUpdatedLabel") 'Control on my Master Page, this can be added to your page insteadv as a labeldocID
  Dim did As String = Page.RouteData.Values("ArticleID").ToString
  Dim com As New SqlCommand("EXEC GetDocument '" & Replace(did, "'", "''") & "'", con)
  con.Open()
  Dim dr = com.ExecuteReader
  While dr.Read()
  HeaderLabel.Text = dr.Item(3).ToString
  ContentText.InnerHtml = httpsUtility.HtmlDecode(dr.Item(4).ToString)
  LastUpdated.Text = Format(CDate(dr.Item(5).ToString), "dd/MM/yyyy")
  Page.Header.Title = dr.Item(3).ToString
  MetaKeywords = dr.Item(6).ToString
  MetaDescription = dr.Item(7).ToString
  End While
  dr.Close()
  con.Close()
  'End If
End If
End Sub

C#

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString);
protected void Page_Load(object sender, System.EventArgs e)
{
 //If Not IsPostBack Then
 if ((Page.RouteData.Values("ArticleID") != null)) {
  Label LastUpdated = Master.FindControl("LastUpdatedLabel");
 //Control on my Master Page, this can be added to your page insteadv as a labeldocID
 string did = Page.RouteData.Values("ArticleID").ToString;
  SqlCommand com = new SqlCommand("EXEC GetDocument '" + Strings.Replace(did, "'", "''") + "'", con);
  con.Open();
  dynamic dr = com.ExecuteReader;
 while (dr.Read()) {
  HeaderLabel.Text = dr.Item(3).ToString;
  ContentText.InnerHtml = httpsUtility.HtmlDecode(dr.Item(4).ToString);
  LastUpdated.Text = Strings.Format(Convert.ToDateTime(dr.Item(5).ToString), "dd/MM/yyyy");
  Page.Header.Title = dr.Item(3).ToString;
  MetaKeywords = dr.Item(6).ToString;
  MetaDescription = dr.Item(7).ToString;
  }
  dr.Close();
  con.Close();
  }
}

ラッピング

これは古い文書ですが、依然として関連するアイデアが含まれていますので、あなたがやっていることは何でもベースとして使用してください!

Helpful?

Please note, this commenting system is still in final testing.

Author

Copyright Claytabase Ltd 2020

Registered in England and Wales 08985867

RSSLoginLink クッキーポリシーサイトマップ

Social Media

facebook.com/Claytabaseinstagram.com/claytabase/twitter.com/Claytabaselinkedin.com/company/claytabase-ltd

Get in Touch

+442392064871info@claytabase.comClaytabase Ltd, Unit 3d, Rink Road Industrial Estate, PO33 2LT, United Kingdom
The settings on this site are set to allow all cookies. These can be changed on our Cookie Policy & Settings page.
By continuing to use this site you agree to the use of cookies.
Ousia Logo
Logout
Ousia CMS Loader