asp.net AJAX: Step by step to create a beautiful news list (no refresh paging, Content Preview) (4)

Source: Internet
Author: User
Tags count

The first three articles came up with one goal: no refresh paging. This article will implement the second goal of previewing news content. There are two ways to get a preview of the content, one for Ajax and one for pseudo Ajax (let's call it that).

We first use pseudo Ajax to achieve news content preview. The simple way to do this is to read the news list and see what's going to be previewed but not on the page, and display the preview when the mouse moves over the link. It's simple to realize,

We can assign the contents of the preview to the title attribute in the hyperlink tag, and then display it in the MouseHover. Here's how to implement a preview of the news.

Here we use a jquery plugin Nicetitle

Nicetitle is a plugin that displays hints when you move the mouse over a hyperlink. We can use this plugin to implement news, text preview.

This is not a real preview that reads the text list while reading the content profile for each article (that is, what you want to preview), and then use the plugin to implement a fake preview.

The effect diagram is as follows, you can modify it accordingly

The code is as follows:

<link rel="Stylesheet" type="text/css"  href="Styles/jQuery.niceTitle.css" />
<script type="text/javascript"  src="Scripts/jQuery.niceTitle.js"></script>
<script type="text/javascript">
$(function () {
$("a[class=info]").niceTitle();
});
</script>
<a href='链接地址' title='预览的内容' class="info">链接名 </a>

The following should be modified in the previous article:

1. Modify query conditions and increase the interception of strings in NewsHandler.ashx.cs

String cmdtext = "Select News_id,news_title,news_readtimes,news_time from" + table + ' ORDER BY ' + order + "desc";

To

String cmdtext = "SELECT * from" + table + ' ORDER BY ' + by + "desc";

and add the following code to control what is returned is the content of the preview rather than the content of the news:

//将dt中news_content的字数都控制在300个字多余的使用...
if (dt != null || dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["news_content"].ToString().Length > 300)
{
dt.Rows[i]["news_content"] = dt.Rows[i]["news_content"].ToString ().Substring(0, 299) + "...";
}
}
}

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.