Javascript:
<script type ="text/javascript">
var
AjaxServerPageName = "AjaxServer.aspx?id=1";
function
CreateXmlReq()
{
try
{
XmlReq = new
ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
XmlReq = new
ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
XmlReq = null;
}
}
if(!XmlReq
&& typeof XMLHttpRequest != "undefined")
{
XmlReq = new
XMLHttpRequest();
}
}
function
HandleResponse()
{
if(XmlReq.readyState
== 4)
{
if(XmlReq.status
== 200)
{
// This Line is Very important.
document.getElementById("GridData").innerHTML =
XmlReq.responseText;
}
else
{
alert("There
was a problem retrieving data from the server." );
}
}
}
function
FetchDGContents()
{
var
requestUrl = AjaxServerPageName;
CreateXmlReq();
if(XmlReq)
{
XmlReq.onreadystatechange =
HandleResponse;
XmlReq.open("GET",
requestUrl, true);
XmlReq.send();
}
--------------------------------------------------------------------
Call This Function on AjaxServer.aspx.cs Load Event
public void ConvertHTML(DataSet
ds)
{
using (StringWriter sw = new
StringWriter())
{
using
(HtmlTextWriter htw = new HtmlTextWriter(sw))
{
string
srtMsg;
//
instantiate a datagrid
DataGrid
dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.HeaderStyle.BackColor =
System.Drawing.Color.Gray;
dg.HeaderStyle.Font.Name = "Tahoma";
dg.HeaderStyle.Font.Size = 12;
dg.HeaderStyle.ForeColor =
System.Drawing.Color.White;
dg.DataBind();
dg.RenderControl(htw);
srtMsg = sw.ToString();
ds.Clear();
Response.Clear();
Response.ContentType = "text/HTML";
Response.Write(srtMsg);
Response.End();
}
}
}
</script>
No comments:
Post a Comment