读取服务器数据填充Select下拉列表[原创]

test.html
None.gif <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
None.gif
< html  xmlns ="http://www.w3.org/1999/xhtml"   >
None.gif
< head >
None.gif    
< title > 测试 </ title >
ExpandedBlockStart.gifContractedBlock.gif    
< script  type ="text/javascript" > dot.gif
InBlock.gif        
var xmlhttp;
InBlock.gif                
function getSubmodule()
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                        xmlhttp 
= new ActiveXObject("Msxml2.XMLHTTP");
InBlock.gif                        xmlhttp.open(
"get","Rss_SubModule.aspx",true);
InBlock.gif                        xmlhttp.setRequestHeader(
"Content-Type","application/x-www-form-urlencoded");
InBlock.gif                        xmlhttp.onreadystatechange 
= ShowList;
InBlock.gif                        xmlhttp.send(
null);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
InBlock.gif                
function ShowList()
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(xmlhttp.readyState == 4)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if(xmlhttp.status == 200)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                           doc 
= new ActiveXObject("Msxml2.DOMDocument")
InBlock.gif                           doc.loadXML(xmlhttp.responseText);
InBlock.gif                            
var items = doc.getElementsByTagName("SubModule");
InBlock.gif                            
InBlock.gif                            
var s = document.getElementById("Select1");
InBlock.gif                            
for(var i= 0;i < items.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                           
dot.gif{
InBlock.gif                                
var op = document.createElement("option");
InBlock.gif                                op.value 
= items[i].getElementsByTagName("SubModuleID")[0].firstChild.nodeValue;
InBlock.gif                                
var tx = document.createTextNode(items[i].getElementsByTagName("SubModuleName")[0].firstChild.nodeValue);
InBlock.gif                                op.appendChild(tx);
InBlock.gif                                s.appendChild(op);
ExpandedSubBlockEnd.gif                           }

ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            alert(xmlhttp.status 
+" : "+ xmlhttp.statusText);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                                               
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif    
function displayText()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif         
for(var i=0 ;i< document.getElementById("Select1").options.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif            
if(document.getElementById("Select1").options[i].selected)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                alert(document.getElementById(
"Select1").options[i].value);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif         }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif   
</ script >
None.gif
</ head >
None.gif
< body >
None.gif    
< input  id ="Button1"  type ="button"  value ="button"  onclick ="getSubmodule()"   />
None.gif    
< select  id ="Select1"  onchange ="displayText()" >
None.gif    
</ select >
None.gif
</ body >
None.gif
</ html >
None.gif

Rss_SubModule.aspx
None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Text;
None.gif
using  System.Xml;
None.gif
using  System.Configuration;
None.gif
using  System.Collections;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
None.gif
public  partial  class  Rss_SubModule : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif();
InBlock.gif        xml.PutSubModule();
ExpandedSubBlockEnd.gif    }

InBlock.gif    
private void PutSubModule()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        SubModule sub 
= new SubModule();
InBlock.gif        DataSet ds 
= sub.GetSubModule();
InBlock.gif        XmlTextWriter w 
= new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
InBlock.gif        w.WriteStartDocument();
InBlock.gif        w.WriteStartElement(
"GetSubModule");
InBlock.gif        
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            w.WriteStartElement(
"SubModule");
InBlock.gif            w.WriteElementString(
"SubModuleID", ds.Tables[0].Rows[i][0].ToString());
InBlock.gif            w.WriteElementString(
"SubModuleName", ds.Tables[0].Rows[i][1].ToString());
InBlock.gif            w.WriteEndElement();
ExpandedSubBlockEnd.gif        }

InBlock.gif        w.WriteEndElement();
InBlock.gif        w.WriteEndDocument();
InBlock.gif        ds.Dispose();
InBlock.gif        w.Close();
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/ghx88/archive/2006/06/25/435428.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值