首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

怎么将四联动DropDownList中的值用存储过程存入数据库,用,用.

2012-02-21 
如何将四联动DropDownList中的值用存储过程存入数据库,急用,急用...C#代码:#regionGetDataSetpublicstatic

如何将四联动DropDownList中的值用存储过程存入数据库,急用,急用...
C#代码:
#region   GetDataSet
public   static   DataSet   GetDataSet(string   sql)
{
SqlDataAdaptersda   =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>

[解决办法]
我这有资源,加我!
给你!呵呵!

热点排行