如何将四联动DropDownList中的值用存储过程存入数据库,急用,急用...

泡面之夏 2007-09-21 11:28:18
C#代码:
#region GetDataSet
public static DataSet GetDataSet(string sql)
{
SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString);
DataSet ds=new DataSet();
sda.Fill(ds);
return ds;
}
#endregion

#region property
private string FirstID
{
get
{
if(ViewState["FirstID"]!=null && ViewState["FirstID"].ToString()!="")
{
return ViewState["FirstID"].ToString();
}
else
{
if(Request["FirstID"]!=null && Request["FirstID"].ToString()!="")
{
return Request["FirstID"];
}
else
{
return "";
}
}
}
set
{
ViewState["FirstID"]=value;
}
}
private string SecondID
{
get
{
if(ViewState["SecondID"]!=null && ViewState["SecondID"].ToString()!="")
{
return ViewState["SecondID"].ToString();
}
else
{
if(Request["SecondID"]!=null && Request["SecondID"].ToString()!="")
{
return Request["SecondID"];
}
else
{
return "";
}
}
}
set
{
ViewState["FirstID"]=value;
}
}

private string ThirdID
{
get
{
if(ViewState["ThirdID"]!=null && ViewState["ThirdID"].ToString()!="")
{
return ViewState["ThirdID"].ToString();
}
else
{
if(Request["ThirdID"]!=null && Request["ThirdID"].ToString()!="")
{
return Request["ThirdID"];
}
else
{
return "";
}
}
}
set
{
ViewState["FirstID"]=value;
}
}
#endregion

#region Page_Load
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
   {
     this.down1_bind();
this.DropDownList1.Attributes.Add("onchange","XmlPost2(this);");
this.DropDownList2.Attributes.Add("onchange","XmlPost3(this);");
this.DropDownList3.Attributes.Add("onchange","XmlPost4(this);");
   }
   if(FirstID != "")
   {
     this.down2_bind(FirstID);
   }
if(SecondID != "")
   {
     this.down3_bind(SecondID);
   }
if(ThirdID != "")
{
this.down4_bind(ThirdID);
}
}

#endregion

#region down2_bind
private void down2_bind(string id)
{
   string mystr = "";
string sql = "select SecondID,SecondName from Column2 where Father = '" + id + "'";
   DataSet ds = GetDataSet(sql);
if(ds.Tables[0].Rows.Count != 0)
   {
     for(int i=0;i<ds.Tables[0].Rows.Count;i++)
     {
mystr += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
     }
     mystr = mystr.Substring(1);
   }
   this.Response.Write(mystr);
   this.Response.End();
}
#endregion

#region down3_bind
private void down3_bind(string id)
{
   string mystr = "";
string sql = "select ThirdID,ThirdName from column3 where Father = '" + id + "'";
   DataSet ds = GetDataSet(sql);

   if(ds.Tables[0].Rows.Count != 0)
   {
     for(int i=0;i<ds.Tables[0].Rows.Count;i++)
     {
mystr += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
     }
     mystr = mystr.Substring(1);
   }
   this.Response.Write(mystr);
   this.Response.End();
}

#endregion

#region down4_bind
private void down4_bind(string id)
{
  string mystr = "";
string sql = "select FourID,FourName from column4 where father = '" + id + "'";
 DataSet ds = GetDataSet(sql);

 if(ds.Tables[0].Rows.Count != 0)
  {
   for(int i=0;i<ds.Tables[0].Rows.Count;i++)
    {
  mystr += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
    }
   mystr = mystr.Substring(1);
  }
  this.Response.Write(mystr);
 this.Response.End();
}

#endregion

#region down1_bind
private void down1_bind()
{
   string sql = "select FirstID,FirstName from Column1";
   DataSet ds = GetDataSet(sql);
   this.DropDownList1.DataSource = ds;
   this.DropDownList1.DataValueField = "FirstID";
   this.DropDownList1.DataTextField = "FirstName";
   this.DropDownList1.DataBind();  
}

#endregion
我的事件代码:------------------------------------------------------------
private void LinkButton1_Click(object sender, System.EventArgs e)
{
if(this.EgonEditor2.Text.Length<=0)
{
Response.Write("<script> alert('内容不能为空,请重新添加!')</script>");
}
else
{

Admin.Conn.ConnDB cdb=new Admin.Conn.ConnDB();

string Drop1=this.Request.Form[DropDownList1.UniqueID].ToString();

string Drop2=this.Request.Form[DropDownList2.UniqueID].ToString();

string Drop3=this.Request.Form[DropDownList3.UniqueID].ToString();

string Drop4=this.Request.Form[DropDownList4.UniqueID].ToString();
HttpPostedFile file=File1.PostedFile;
string image;
if(file.FileName=="") image="images.gif";
else
image=Path.GetFileName(file.FileName);
file.SaveAs(MapPath("ProIMages")+"//"+image); cdb.InsertIntoProducts(txttitle.Text,EgonEditor2.Text,image,Drop1,Drop2,Drop3,Drop4);
Response.Write("<script> alert('添加成功!')</script>");
}
}

html代码:----------------------------------------------------------------

<SCRIPT language="JavaScript">
<!--
//以XML求取DropDownList2的数据
function XmlPost2(obj)
{
   var svalue = obj.value;
   var webFileUrl = "?Firstid=" + svalue;
   var result = "";
   var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
   xmlHttp.open("POST", webFileUrl, false);
   xmlHttp.send("");
   result = xmlHttp.responseText;
  
   if(result != "")
   {
     document.all("DropDownList2").length=0;
     var piArray = result.split(",");
     for(var i=0;i<piArray.length;i++)
     {
       var ary1 = piArray[i].toString().split("|");
       document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
     }
   }
   else
   {
     alert(result);
   }
}
//以XML求取DropDownList3的数据
function XmlPost3(obj)
{
   var svalue = obj.value;
   var webFileUrl ="?SecondID=" + svalue;
   var result = "";
   var xmlHttp= new ActiveXObject("MSXML2.XMLHTTP");
   xmlHttp.open("POST", webFileUrl, false);
   xmlHttp.send("");
   result = xmlHttp.responseText;
  
   if(result != "")
   {
     document.all("DropDownList3").length=0;
     var piArray = result.split(",");
     for(var i=0;i<piArray.length;i++)
     {
       var ary1 = piArray[i].toString().split("|");
       document.all("DropDownList3").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
     }
   }
   else
   {
     alert(result);
   }
}


//以XML求取DropDownList4的数据
function XmlPost4(obj)
{
   var svalue = obj.value;
   var webFileUrl ="?ThirdID=" + svalue;
   var result = "";
   var xmlHttp= new ActiveXObject("MSXML2.XMLHTTP");
   xmlHttp.open("POST", webFileUrl, false);
   xmlHttp.send("");
   result = xmlHttp.responseText;
  
   if(result != "")
   {
     document.all("DropDownList4").length=0;
     var piArray = result.split(",");
     for(var i=0;i<piArray.length;i++)
     {
       var ary1 = piArray[i].toString().split("|");
       document.all("DropDownList4").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
     }
   }
   else
   {
     alert(result);
   }
}

-->
</SCRIPT>
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
泡面之夏 2007-10-17
  • 打赏
  • 举报
回复
谢谢了
chenlu_530 2007-10-17
  • 打赏
  • 举报
回复
我这有资源,加我!
给你!呵呵!
泡面之夏 2007-10-11
  • 打赏
  • 举报
回复
算了自己解决了,这个就不用了,我自己做的已经上传了,有兴趣的可以看一下。

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧