Implement fck news paging in ASP. NET

Source: Internet
Author: User

Here we implement a simple function of paging news content using fck.

 

Three files need to be manually created for the entire demo

 

1. Add a news content page to fck; 2. display a paging effect page; 3. Paging Processing

 

In order not to waste valuable time on friends seeking for paging help, first check if you want it. If so,

 

Let's look at it. It seems that this "mean" cannot upload attachments.

 

 

I will upload the demo to the shared resource.

 

Add news

 

 

 

Click Add to display the page:

 

 

If the first page, the next page, and the next page are displayed, only the page number and the previous page are displayed. add the relevant code to the CS class.

 

 

The following describes the specific operations.

 

First, create a website named fckpagestest.

 

Copy the fck file package "FCKeditor" to the project, and find FCKeditor/Editor/JS/to replace the two JS classes in the demo.

 

The names are fckeditorcode_gecko.js and fckeditorcode_ie.js.

 

Find the fckconfig. js file under "FCKeditor" and open the file. Three operations are required here:

 

I:

Fckconfig 51 fckconfig. pluginspath = fckconfig. basepath + 'ins INS/'; then add
Fckconfig. plugins. Add ('insertpage', 'zh-cn ');
Fckconfig. plugins. Add ('flvplayer', 'zh-cn ');

 

 

II:

Fckconfig. defaultlanguage = 'en'; change
Fckconfig. defaultlanguage = 'zh-cn ';

 

 

III:

In the default function item fckconfig. toolbarsets ["default"] =

Add 'pagebreak' to the following items'

 

I have added most of the functions here, but for your convenience, I have pasted the code in the options here. The red is what we just added:

 

Fckconfig. toolbarsets ["default"] = [
['Source'],
['Cut ', 'copy', 'paste', 'pastetext ', 'pasteword','-', 'print', 'spellcheck'],
['Undo ', 'redo', '-', 'Find ', 'replace', '-', 'selectall', 'removeformat'],
['Bold ', 'italic', 'underline', 'strikethangout', '-', 'subscript', 'superscript'],
['Orderedlist', 'unorderedlist', '-', 'outdent ', 'indent', 'blockquote'],
['Justifyleft', 'justifycenter', 'justifyright', 'justifyfull'],
['Link', 'unlink', 'anchor '],
['Image', 'flash', 'table', 'rule', 'smilil', 'specialchar ', 'flvplayer', 'pagebreak'],
['Fontformat', 'fontname', 'fontsize'],
['Textcolor', 'bgcolor'],

];

 

 

 

So far, the fck paging preparation work has been completed, and the driver's license has to go on the road. In the website we just created, add the ASPX page name: addnews. aspx: register the fck control. Of course, if you drag the tool directly from the page, it will help you register this step. And equipped with: basepath

 

I:

Register fck

<% @ Register Assembly = "fredck. fckeditorv2" namespace = "fredck. fckeditorv2" tagprefix = "fckeditorv2" %>

II:

<Fckeditorv2: FCKeditor id = "fcknewscontent" runat = "server" width = "700px" Height = "400px"
Basepath = "FCKeditor/">
</Fckeditorv2: FCKeditor>

 

Look at the fck control. Is the paging character found at the end of the toolbar?

 

At this time, you can insert the news content directly as shown in the previous figure. Add a paging character to the place where the line feed is needed.

 

 

Next, we will deal with the pagination class getpage. cs. There are not many codes, and only 70 lines are added with comments and line breaks. The red comments

 

Points, which are explained here, if you query by number

 

, Then directly input the string new_guid parameter to uncomment the comments. Because this is only a demo

 

After adding news, the content is directly displayed.

 

.

 

 

Using system;
Using system. text;
Using system. Text. regularexpressions;

/// <Summary>
/// Summary of getpage
/// </Summary>
Public class getpage
{
/// <Summary>
/// Pagination of news content
/// </Summary>
/// <Param name = "content"> content to be paged </param>
/// <Returns> current page news content </returns>
Public static string newscontentpager (string content, string new_guid)
{
If (content = NULL)
{
Return NULL;
}
Content = enhtml (content );
String P = "// [page //]";
If (content. indexof ("[Page]")! =-1)
{
String page = system. Web. httpcontext. Current. Request. querystring ["page"];
String [] arrcontent = RegEx. Split (content, P, regexoptions. ignorecase );
Int pagesize = arrcontent. length;
If (string. isnullorempty (page ))
Page = "0 ";
If (Int. parse (PAGE)> = pagesize)
{
System. Web. httpcontext. Current. response. statuscode = 404;
System. Web. httpcontext. Current. response. End ();
}
// Generate the page number
Stringbuilder sb = new stringbuilder ();
SB. append (arrcontent [Int. parse (PAGE)]. tostring ());
SB. append ("<Div id =/" newspager/"class =/" newpager/"> ");
If (Int. parse (PAGE)> 0)
// Sb. appendformat ("<a href = /"? Page = {0} & news_guid = {1}/"> previous page </a> & nbsp;", Int. parse (PAGE)-1, new_guid );
SB. appendformat ("<a href = /"? Page = {0}/"> previous page </a> & nbsp;", Int. parse (PAGE)-1 );

For (INT I = 0; I <pagesize; I ++)
{
If (I = int. parse (page ))
SB. appendformat ("& nbsp; <span >{0} </span> & nbsp;", I + 1 );
Else
{
// Sb. appendformat ("& nbsp; <a href = /"? Page = {0} & news_guid = {1}/"> {2} </a> & nbsp;", I, new_guid, I + 1 );
SB. appendformat ("& nbsp; <a href = /"? Page = {0}/">{1} </a> & nbsp;", I, I + 1 );
}
}
If (Int. parse (PAGE) <pagesize-1)
// Sb. appendformat ("<a href = /"? Page = {0} & news_guid = {1}/"> next page </a> & nbsp;", Int. parse (PAGE) + 1, new_guid );
SB. appendformat ("<a href = /"? Page = {0}/"> next page </a> & nbsp;", Int. parse (PAGE) + 1 );
SB. append ("</div> ");
Return sb. tostring ();
}
Else
{
Return content;
}
}

Public static string enhtml (string Str)
{
If (STR = NULL)
Return "";
STR = Str. Replace ("<div> [Page] </div>", "[Page]");
STR = Str. Trim ();
Return STR;
}
}

 

 

Take your driver's license and go to the high-speed entrance. Start to enjoy driving.

 

Finally, you only need to pass the news content into the processing method, wait for the returned result, and output it to the interface.

 

 

 

Demo: fck news paging demo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.