var http_request=false; function createrequest() { http_request=false; if(window.XmlHttpRequest) { http_request=new XmlHttpRequest(); if(http_request.overrideMimeType) { http_request.overrideMimeType("text/xml"); } } else { try { http_request=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { http_request=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){} } } } function disPlay(str) { if(str==1) { document.getElementById("btn_Add").value="添加一级"; } if(str==2) { document.getElementById("btn_Add").value="添加二级"; } document.getElementById("txtSort").value=""; document.getElementById("layer").style.display='block'; } function OutdisPlay() { document.getElementById("layer").style.display='none'; } function one() { if(http_request.readyState==4) { if(http_request.status==200) { var sort=document.getElementById("txtSort").value; var drplist=document.getElementById(''); var id=http_request.responseText; var optNew=document.createElement('option'); optNew.text=sort; optNew.value=id; drplist.add(optNew); drplist.selectedValue=id; drplist.selectedIndex=drplist.options.length-1; } } } function two() { if(http_request.readyState==4) { if(http_request.status==200) { var sort=document.getElementById("txtSort").value; var drplist=document.getElementById(''); var sid=http_request.responseText; var optNew=document.createElement('option'); optNew.text=sort; optNew.value=sid; drplist.add(optNew); drplist.selectedValue=sid; drplist.selectedIndex=drplist.options.length-1; } } } function submitOnerequest(str) { if(document.getElementById("btn_Add").value=="添加一级") { createrequest() var sort=document.getElementById("txtSort").value; var url='UseAjax.aspx?sort='+escape(sort); // send_request("GET",url,null,"text",callback); http_request.open("GET",url,true); http_request.onreadystatechange=one; http_request.send(null); // var sort=document.getElementById("txtSort").value; } if(document.getElementById("btn_Add").value=="添加二级") { createrequest(); var sort=document.getElementById("txtSort").value; var drpBsort=document.getElementById(''); if(drpBsort.selectedValue=="") { window.alert("请选择一级分类"); OutdisPlay() } var id=drpBsort.selectedValue; var url='UseAjax.aspx?sort='+escape(sort)+'&id='+escape(id); http_request.open("GET",url,true); http_request.onreadystatechange=two; http_request.send(null); // send_request("GET",url,null,"text",callback); } document.getElementById("layer").style.display='none'; }
商家一级分类<br />
<asp:DropDownList ID="drpListBsort" runat="server" Width="106px" AutoPostBack="True" OnSelectedIndexChanged="drpListBsort_SelectedIndexChanged">
</asp:DropDownList><br />
<a href="javascript:" οnclick="disPlay(1)">添加分类</a>
<br />
商品二级分类<br />
<asp:DropDownList ID="drpListSsort" runat="server" Width="103px">
</asp:DropDownList>
<a href="javascript:" οnclick="disPlay(2)">添加分类</a>
<div id="layer" style=" height:50px; left:150px; top:1050px; background-color:AntiqueWhite; display:none;">
<input type="text" id="txtSort" /><br />
<input type="button" id="btn_Add" value="添加" οnclick="submitOnerequest(this.value)"/>
<input type="button" id="btn_Close" value="关闭" οnclick="OutdisPlay()" />
</div>
在'UseAjax.aspx页面的代码
DataBase db=new DataBase();
string sql = "";
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
if (Request.QueryString["id"] == null && Request.QueryString["sort"]!=null)
{
sql = "insert into City_Product_Bsort(Bname) values('"+Request.QueryString["sort"].ToString()+"');select @@identity as id";
int id=Convert.ToInt32(db.ExecuteScalar(sql));
if (id>0)
{
Response.Write(id.ToString());
}
}
if (Request.QueryString["id"] != null && Request.QueryString["sort"] != null)
{
sql = "insert into City_Product_Ssort(Sname,Bid) values('"+Request.QueryString["sort"].ToString()+"',"+Request.QueryString["id"].ToString()+");select @@identity as id";
int id = Convert.ToInt32(db.ExecuteScalar(sql));
if(id>0)
{
Response.Write(id.ToString());
}
}
}
}