濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > ajax 數(shù)據(jù)庫(kù)中隨機(jī)讀取5條數(shù)據(jù)動(dòng)態(tài)在頁(yè)面中刷新

ajax 數(shù)據(jù)庫(kù)中隨機(jī)讀取5條數(shù)據(jù)動(dòng)態(tài)在頁(yè)面中刷新

熱門標(biāo)簽:姜堰電銷機(jī)器人 遼寧銀行智能外呼系統(tǒng) 上海浦東騰訊地圖標(biāo)注位置 遼寧正規(guī)電銷機(jī)器人 電銷機(jī)器人違法了嗎 許昌智能電銷機(jī)器人公司 澳大利亞城市地圖標(biāo)注 辰溪地圖標(biāo)注 海南銀行智能外呼系統(tǒng)商家
不能用數(shù)據(jù)庫(kù)中的Top,后面發(fā)現(xiàn)了用這樣一個(gè)方法可以實(shí)現(xiàn)。?!,F(xiàn)就這個(gè)方法總結(jié)寫了一個(gè)頁(yè)面。有興趣的朋友們可以一起學(xué)習(xí)下。。。。
前臺(tái)代碼: 
復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajaxRandomData.aspx.cs" Inherits="ajaxRandomData" %>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w3.org/1999/xhtml" >
head runat="server">
title>ajax隨機(jī)生成數(shù)據(jù)/title>
script language="javascript" type="text/javascript" src="ajax/jquery.js">/script>
script >
//頁(yè)面的初始化
$(document).ready(function(){randomData()});
//頁(yè)面初始化函數(shù)
function randomData()
{
$.ajax({
type:'POST',
url:'ajaxRandomData.aspx',
data:{action:'randon'},
success:randomDatacallbace
});
}
// 頁(yè)面初始化回調(diào)函數(shù)
function randomDatacallbace(data)
{
if(data=="")
{
alert("暫時(shí)不能為您生成數(shù)據(jù)");
$("#randomData").html("暫時(shí)不能為您生成數(shù)據(jù)");
}
else
{
$("#randomData").html(data);
randomtime();//每隔5秒鐘執(zhí)行一次
}
}
//動(dòng)態(tài)變化頁(yè)面中顯示的數(shù)據(jù)。
function randomtime()
{
setTimeout(function(){randomData()},2000)
}
/script>
/head>
body>
form id="form1" runat="server">
div style="text-align:center" id="randomData">
/div>
/form>
/body>
/html>

后臺(tái)代碼:
復(fù)制代碼 代碼如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
public partial class ajaxRandomData : System.Web.UI.Page
{
string StrAction = "";
protected void Page_Load(object sender, EventArgs e)
{
StrAction=Request["action"];
if(StrAction=="randon")
{
InitData();
}
}
/// summary>
///創(chuàng)建人:周昕
/// 創(chuàng)建時(shí)間:2009-6-9
/// 方法名稱:InitData
/// 方法作用:動(dòng)態(tài)的生成表格并隨機(jī)的生成5條數(shù)據(jù)
/// /summary>
public void InitData()
{
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
//隨機(jī)生成數(shù)據(jù)的關(guān)鍵
string sql = "select top 5 *,newid() from loginuser order by newid()";
SqlDataAdapter myda = new SqlDataAdapter(sql, mycon);
DataSet myset = new DataSet();
myda.Fill(myset);
DataTable mytable = myset.Tables[0];
int n = mytable.Rows.Count;
StringBuilder str = new StringBuilder();
str.Append("table style='text-align:left;color:red;width:600px'>tr style='color:#00FF00;font-size:40px;text-align:center'>td colspan='3'>動(dòng)態(tài)刷新用戶信息/td>/tr>tr style='color:#6600FF'>td style='text-align:left;width:100px'>用戶名/td>td style='text-align:left;width:200px'>用戶全名/td>td style='width:250px'>電子油箱/td>/tr>");
for (int i = 0; i n; i++)
{
string username = mytable.Rows[i]["username"].ToString();
string fullname = mytable.Rows[i]["FullName"].ToString();
string email = mytable.Rows[i]["Email"].ToString();
if (i % 2 != 0)
{
str.Append("tr>td>" + username + "/td>");
str.Append("td>" + fullname + "/td>");
str.Append("td>" + email + "/td>/tr>");
}
else
{
str.Append("tr style='color:blue'>td>" + username + "/td>");
str.Append("td>" + fullname + "/td>");
str.Append("td>" + email + "/td>/tr>");
}
}
str.Append("/table>");
Response.Clear();
Response.ContentType = "application/text";
Response.Write(str);
Response.End();
}
}

效果圖

您可能感興趣的文章:
  • jquery+php隨機(jī)生成紅包金額數(shù)量代碼分享
  • js jquery獲取隨機(jī)生成id的服務(wù)器控件的三種方法
  • Js 代碼中,ajax請(qǐng)求地址后加隨機(jī)數(shù)防止瀏覽器緩存的原因
  • 基于JQuery及AJAX實(shí)現(xiàn)名人名言隨機(jī)生成器

標(biāo)簽:威海 伊春 晉城 崇左 深圳 銅川 撫州 西藏

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ajax 數(shù)據(jù)庫(kù)中隨機(jī)讀取5條數(shù)據(jù)動(dòng)態(tài)在頁(yè)面中刷新》,本文關(guān)鍵詞  ajax,數(shù)據(jù)庫(kù),中,隨機(jī),讀取,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ajax 數(shù)據(jù)庫(kù)中隨機(jī)讀取5條數(shù)據(jù)動(dòng)態(tài)在頁(yè)面中刷新》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于ajax 數(shù)據(jù)庫(kù)中隨機(jī)讀取5條數(shù)據(jù)動(dòng)態(tài)在頁(yè)面中刷新的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    大邑县| 邵阳县| 澄江县| 安义县| 师宗县| 大邑县| 安丘市| 湖口县| 静乐县| 刚察县| 淮北市| 泊头市| 平舆县| 古田县| 白朗县| 余江县| 宁明县| 股票| 阜宁县| 双桥区| 北票市| 商丘市| 玛沁县| 时尚| 保定市| 慈溪市| 东宁县| 武宁县| 莱芜市| 饶河县| 乌什县| 内江市| 大荔县| 广平县| 怀仁县| 西贡区| 邢台县| 镇江市| 秭归县| 吕梁市| 建德市|