[sourcecode language="html"]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="showdata.aspx.cs" Inherits="showdata" %>
<!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>Untitled Page</title></head>
<body onload="getDataSet();">
<form id="form1" runat="server">
<script language=javascript>
function getDataSet()
{
showdata.getdata(GetDataSet_callback);
}
function GetDataSet_callback(response)
{
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{var s = new Array();
s[s.length] = "<table border=1>";
for(var i=0; i<ds.Tables[0].Rows.length; i++){
s[s.length] = "<tr>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].companyname + "</td>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].address + "</td>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].email1 + "</td>";
s[s.length] = "</tr>";
}
s[s.length] = "</table>";
tableDisplay.innerHTML = s.join("");
}
else{
alert("Error. [3001] " + response.request.responseText);
}
window.setTimeout(getDataSet,3000);
}
</script>
<div id="tableDisplay"></div>
<input type=button id="btn" onclick="getDataSet()" value="show" />
</form>
</body>
</html>
[/sourcecode]
[sourcecode language="csharp"]
using System;
using System.Data;
using System.Data.SqlClient;
usingSystem.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;
public partial class showdata : System.Web.UI.Page
{
public static int i = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
protected void Page_Load(object sender, EventArgs e)
{Ajax.Utility.RegisterTypeForAjax(typeof(showdata));
}
[Ajax.AjaxMethod()]
public DataSet getdata()
{SqlDataAdapter cmd = new SqlDataAdapter("select companyname,address,email1 from registration where regdate=@cdate", con);
cmd.SelectCommand.Parameters.Add("@cdate", SqlDbType.DateTime).Value = Convert.ToDateTime("2/26/2007").AddDays(i++); ;
DataSet ds = new DataSet();
cmd.Fill(ds);
return ds;
}
}
[/sourcecode]
No comments :
Post a Comment