First, we will use Ajax. NETProfessional today. you can obtain relevant information about ajax.netfrom http://www.schwarz-interactive.de. You also need to know about XML data Island. Next, let's look at a simple binding example.
First we will use Ajax. NET Professional today, you can get relevant information about AJAX. NET from http://www.schwarz-interactive.de. You also need to know about XML data Island. Next we will look at a simple binding example:
Step 1 determine the XML data source
Reference content is as follows:
<Xml ID = "xmlData" name = "xmlData">
<Root>
<METADATA>
<AUTHOR> John Smith </AUTHOR>
<GENERATOR> Visual Notepad </GENERATOR>
<PAGETYPE> Reference </PAGETYPE>
<ABSTRACT> Specifies a data island </ABSTRACT>
</METADATA>
<METADATA>
<AUTHOR> John Smith2 </AUTHOR>
<GENERATOR> Visual Notepad2 </GENERATOR>
<PAGETYPE> Reference2 </PAGETYPE>
<ABSTRACT> Specifies a data island2 </ABSTRACT>
</METADATA>
<METADATA>
<AUTHOR> John Smith3 </AUTHOR>
<GENERATOR> Visual Notepad3 </GENERATOR>
<PAGETYPE> referenpushed </PAGETYPE>
<ABSTRACT> Specifies a data island3 </ABSTRACT>
</METADATA>
</Root>
</Xml>
Step 2: bind the container. here we use Table
Reference content is as follows:
<TABLE dataSrc = "# xmlData" border = 1>
<TR>
<TD> <span Dataworks = "AUTHOR"> loading... </span> </TD>
<TD> <span Dataworks = "GENERATOR"> loading... </span> </TD>
<TD> <span Dataworks = "PAGETYPE"> loading... </span> </TD>
<TD> <span Dataworks = "ABSTRACT"> loading... </span> </TD>
</TR>
</TABLE>
Copy the two pieces of code to your HTMl page and run it to see the effect.
The first section is our XML data source, that is, the data to be bound. the METADATA node is equivalent to the table name, AUTHOR, GENERATOR, PAGETYPE, and ABSTRACT are equivalent to the column names, the following Table is a container used to display data. <TABLE dataSrc = "# xmlData" border = 1> is the data source of the specified Table. <span Dataworks = "AUTHOR"> loading... </span> is used to bind the field name.
Now, let's take a look at how to use Ajax to implement the unrefresh binding.
Step 1: Configure Ajax and add the configuration section to the Web. config file:
Reference content is as follows:
<HttpHandlers>
<Add verb = "POST, GET" path = "ajaxpro/*. ashx" type = "AjaxPro. AjaxHandlerFactory, AjaxPro"/>
</HttpHandlers>
Step 2: write the code for the returned dataset:
Reference content is as follows:
Public class MyClass
{
[AjaxMethod]
Public string GetDataSet ()
{
DataSet dst = new DataSet ();
DataTable dt = new DataTable ();
Dt. Columns. Add ("Text ");
Dt. Columns. Add ("Number ");
Random random = new Random (Guid. NewGuid (). GetHashCode ());
For (int I = 0; I <random. Next (10, 20); I ++)
{
DataRow row = dt. NewRow ();
Row ["Text"] = Guid. NewGuid (). ToString ("N ");
Row ["Number"] = random. Next (100 );
Dt. Rows. Add (row );
}
Dst. Tables. Add (dt );
String text = "";
Using (MemoryStream MS = new MemoryStream ())
{
Dst. WriteXml (MS );
Ms. Position = 0;
StreamReader sr = new StreamReader (MS );
Text = sr. ReadToEnd ();
}
Return text;
}
}
Step 3: register this method in Page_Load. AjaxPro. Utility. RegisterTypeForAjax (typeof (WebTest1.AjaxTest1); (WebTest1 is the namespace name)
Step 4: Add client binding
Reference content is as follows:
<INPUT onclick = "WebTest1.MyClass. GetDataSet (callback)" type = "button" value = "GetDataSet">
<Div id = "oDataPanel">
</Div>
<TABLE datasrc = "# xmlData" WIDTH = "500" BORDER = "1" CELLSPACING = "1" CELLPADDING = "1">
<Thead>
<Tr>
<Th width = "70%" type = "parmname" text = "parmname"> Name </th type = "parmname" text = "/parmname">
& Lt; th width = "30%" & gt; age & lt;/th & gt;
</Tr>
</Thead>
<TR>
<TD> <span Dataworks = "Text"> </span> </TD>
<TD> <span Dataworks = "Number"> </span> </TD>
</TR>
</TABLE> <div id = "oDataPanel"> is a container used to store Xml data sources.
Step 5: compile the JavaScript code for loading data
Reference content is as follows:
Function callback (res)
{
If (! Res. error)
{
Document. all. oDataPanel. innerHTML = '<xml id = "xmlData">' + res. value + '</xml> ';
}
Else
{
Alert (res. error. Message );
}
}