Call page triggered by event
<Asp: dropdownlist id = "ddlagentcity" runat = "server" onchange = "onagentcitychange ();"> </ASP: dropdownlist>
Corresponding function. Call the preceding page to obtain the dataset Using ajax, and locate the corresponding record.
- Function onagentcitychange ()
- {
- VaR city = $ ("# <% = ddlagentcity. clientid %>"). Val ();
- $. Ajax (
- {
- URL: '<% = pageutility. getrooturl () %>/order/report/XML/getcompanybycity. aspx? City = '+ city,
- Type: 'get ',
- Datatype: 'xml ',
- Timeout: 10000,
- Error: function ()
- {
- Alert ('error loading XML document ');
- },
- Success: function (XML)
- {
- VaR STR = "";
- $ (XML). Find ("root"). Find ("item"). Each (function ()
- {
- STR + = "<option value = '" + $ (this ). ATTR ("ID") + "'>" + $ (this ). ATTR ("name") + "</option>"
- });
- $ ("# <% = Ddlagentid. clientid %>" example .html (STR );
- }
- });
- }
The last sentence is direct assignment.
The following is a page for querying databases. A collection in XML format is returned.
Public class getcitybyarearegion: system. Web. UI. Page
Private void page_load (Object sender, system. eventargs E)
{
String strarea = request. querystring ["area"];
If (strarea = NULL)
Strarea = "";
Xmldocument Doc = new xmldocument ();
Doc. loadxml ("<? XML version =/"1.0/" encoding =/"gb2312/"?> /N <root/> ");
Ilist lst;
If (strarea. Trim () = "")
{
LST = city. getallcitys ();
}
Else
{
LST = city. getbyarearegion (strarea );
}
Stringbuilder buffer = new stringbuilder ();
Buffer. append ("<root> ");
Buffer. append ("<item code =/"/"name =/" All/"/> ");
For (INT I = 0; I <lst. Count; I ++)
{
Cityinfo info = (cityinfo) lst [I];
Buffer. appendformat ("<item code =/" {0}/"name =/" {1}/"/> ",
Info. strname, info. strcodename );
}
Buffer. append ("</root> ");
Doc. documentelement. innerxml = buffer. tostring ();
Response. contenttype = "text/XML ";
Doc. Save (response. outputstream );
Response. End ();
}
Of course, remember to introduce Js.
<Script language = "JavaScript" src = "<% = pageutilitytool. getrooturl () %>/JS/jquery. js"> </SCRIPT>
Jquery Chinese community http://wiki.jquery.org.cn/doku.php