| |

VerySource

 Forgot password?
 Register
Search
View: 758|Reply: 6

The problem has not been solved for two days, now I will explain it in detail, please help

[Copy link]

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-14 19:30:02
| Show all posts |Read mode
Table 1 (department):

sortid sort
1 R & D Department
2 Finance Department

Table two (name):
typeid typename sortid
1 sheet three 1
2 Li Si 2
3 Wang Wu 1

Table III (complete data):
id typename typeid sort wenti ipaddress
1 sheet 3 1 R & D network is down 192.168.0.8
2 Li Si 2 Finance Department Printer failed 192.168.0.10


I found a piece of code on the Internet to achieve linkage


Now I want to transfer the department, name, question, and IP to data sheet three through linkage.

cm.Parameters.Add (new SqlParameter ("@ usort", SqlDbType.VarChar, 50));
cm.Parameters.Add (new SqlParameter ("@ utypename", SqlDbType.VarChar, 50));
cm.Parameters.Add (new SqlParameter ("@ uwenti", SqlDbType.VarChar, 50));
cm.Parameters.Add (new SqlParameter ("@ ipaddress", SqlDbType.VarChar, 50));
cm.Parameters ["@ usort"]. Value = mydown1.SelectedItem.Value; // Is this place written like this
cm.Parameters ["@ utypename"]. Value = mydown1.SelectedItem.Value; // Is this place written like this
cm.Parameters ["@ uwenti"]. Value = t1.Text;
cm.Parameters ["@ ipaddress"]. Value = Request.UserHostAddress;
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-6-12 21:45:01
| Show all posts
The linkage code is like this

html

<SCRIPT language="JavaScript">
<!--
//Get data in XML
//Parameters:
//obj, the drop-down box of the current action
//fullName: the drop-down box to be filled
function XmlPost(obj,fullName)
{
//Get the value of the current drop-down box
   var svalue = obj.value;
   //Define the object to be filled
   var fullObj = document.all(fullName);
  
   //Define the value address
   var webFileUrl = "?sortid=" + svalue;
  
   //Define the return value
   var result = "";
  
   //Start the value process
   var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
   xmlHttp.open("POST", webFileUrl, false);
   xmlHttp.send("");
   result = xmlHttp.responseText;

  //If there is a value, it will be split according to the format
  //Note that if you select the first line "please select" a blank line, you can not get the value, so an additional condition is added
   if(result != ""&&svalue != "")
   {
   //First clear the original value
     fullObj.length=0;
    
     //Split the value into an array
     var piArray = result.split(",");
    
     //Circular array
     for(var i=0;i<piArray.length;i++)
     {
     // Then split into ID and name
       var ary1 = piArray[i].toString().split("|");
       //Add items one by one
       fullObj.options.add(new Option(ary1[1].toString(),ary1[0].toString()));
    }
  }
   else
   {
     //If no value is obtained, clear the value of the drop-down box to be filled
     fullObj.length = 0;
     fullObj.options.add(new Option("Please select",""));
  }
}
//-->
</SCRIPT>
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-6-12 23:00:01
| Show all posts
The server side is like this

private DataTable Get_Dt(string sql)
{

String strConnection=ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection=new SqlConnection(strConnection);

myConnection.Open();



            SqlDataAdapter myAdp=new SqlDataAdapter(sql,myConnection);

DataTable myDt = new DataTable();

try
{
                                //Data input
myAdp.Fill(myDt);
//Return the data set
return(myDt);
}
catch(OleDbException ex)
{
//Display error message
throw ex;
}
finally
{
//Close the database connection
myConnection.Close();
}
}

private void Page_Load(object sender, System.EventArgs e)
{
//Receive parameters
string sortid = this.Request.QueryString["sortid"];
//Determine whether the parameter is empty (Note: There are two forms of empty, one is null and one is empty)
if(sortid + "a" != "a")
{
//If the above parameters are passed, it means that the linkage operation starts
this.xmlBind(sortid);
}

//When the page is first loaded, bind the first/second drop-down box, the second drop-down box is all values
// But in fact, the second drop-down box should display empty values, because all the values ​​may also be quite a lot, it is best to display only a word "please select"
if(!this.IsPostBack)
{
this.DownBind1();
this.DownBind2();
}
}

private void xmlBind(string sortid)
{
string mystr = "";
string sql = "select typename,typeid from class_2 where sortid = "+ sortid;
DataTable mytab = this.Get_Dt(sql);

//Form the obtained values: ID|Name, ID|Name...
if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i]["typeid"].ToString() + "|" + mytab.Rows[i]["typename"].ToString();
}
mystr = mystr.Substring(1);
}

//Output page
this.Response.Write(mystr);
this.Response.End();
}

/// <summary>
/// Bind the first drop-down box
/// </summary>
private void DownBind1()
{
//Show all main categories
string sql = "select sortid,sort from class_1 order by sortid asc ";
DataTable mytab = this.Get_Dt(sql);

//Bind the first drop-down box
this.mydown1.DataSource = mytab;
this.mydown1.DataValueField = "sortid";
this.mydown1.DataTextField = "sort";
this.mydown1.DataBind();

//Add a "Please select" line
this.mydown1.Items.Insert(0,new ListItem("Please select category",""));

//Add a default selection for this drop-down box (here default is sortid = 1
//When making an option, if you add the selected item and there is no item in this control, an error will occur
//For example: this.mydown1.SelectedValue = "1";
//So here is selected as follows
ListItem myItem = this.mydown1.Items.FindByValue("1");
if(myItem != null)
{
myItem.Selected = true;
}

this.mydown1.Attributes.Add("onchange","XmlPost(this,'" + this.mydown2.ClientID + "');");
}
The

private void DownBind2()
{
//The default is to display all subcategories with classification number 1
   string sql = "select sortid,typename,typeid from class_2 where sortid =1";
   DataTable mytab = this.Get_Dt(sql);

//Fix the control
   this.mydown2.DataSource = mytab;
   this.mydown2.DataSource = mytab;
   this.mydown2.DataValueField = "typeid";
   this.mydown2.DataTextField = "typename";
   this.mydown2.DataBind();

//Add an empty first line
this.mydown2.Items.Insert(0,new ListItem("Please choose a name",""));
}
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-19 14:00:02
| Show all posts
gosh! ! It’s so dizzy to put so many tables on such a simple question~
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-6-25 01:15:01
| Show all posts
Let me talk about simple questions,

Mainly linkage
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-26 07:30:01
| Show all posts
Re-define a table, it will not be OK if you bind it again, check it online
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-6-26 17:15:01
| Show all posts
Table 3 has been re-arranged
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list