| |

VerySource

 Forgot password?
 Register
Search
View: 895|Reply: 7

How to get the value of linkage DROPDOWNLIST on the server side (detailed description)

[Copy link]

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-12-10 15:30:01
| Show all posts |Read mode
My current linkage menu has been implemented, and the following is the code. People who are passing by can help me see it.

Mainly to realize the linkage between the departments of the two dropdownlists and the names, plus the value of a textbox, and submit them to Table 3 together.


My database is as follows, please help experts to see if it is correct.


Table 1 (Department):
sortid sort
1 R&D Department
2 Finance Department

Table 2 (Name):
typeid typename sortid
1 three 1
2 Li Si 2
3 King Five 1

Table 3 (all data):
id typename typeid sort wenti ipaddress
1 Zhang San 1 R&D department network is down 192.168.0.8
2 Li Si 2 Finance Department Printer is not working 192.168.0.10



Stored procedure:

CREATE proc classdata
@usort varchar(50),
@utypename varchar(50),
@uwenti varchar(50)
as
insert into class_data (sort,typename,wenti) values ​​(@usort, @utypename, @uwenti)
GO


aspx.cs code:

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 fetched value: ID|name,ID|name...this form
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();
}


private void DownBind1()
{
//Display all main categories
string sql = "select sortid,sort from class_1 order by sortid asc ";
DataTable mytab = this.Get_Dt(sql);

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

this.mydown1.Items.Insert(0,new ListItem("Please select a category",""));
To
ListItem myItem = this.mydown1.Items.FindByValue("1");
if(myItem != null)
{
myItem.Selected = true;
}

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

private void DownBind2()
{
//By default, all subcategories with category number 1 are displayed
   string sql = "select sortid,typename,typeid from class_2 where sortid =1";
   DataTable mytab = this.Get_Dt(sql);

//Tie the controls
   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 select a name",""));
}
Reply

Use magic Report

1

Threads

60

Posts

37.00

Credits

Newbie

Rank: 1

Credits
37.00

 China

Post time: 2020-12-10 16:30:01
| Show all posts
This is used where the insert statement is executed
DropDownList1.SelectValue.ToString();
DropDownList2.SelectValue.ToString();
TextBox1.Text
Execute stored procedure
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-12-10 17:00:01
| Show all posts
This is how I use it, and it fails.


Request.Form["mydown1"].ToString();
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 United States

Post time: 2020-12-10 17:15:01
| Show all posts
object paramValue = Request.Form["mydown1"];
paramValue = (object.Equals(paramValue,string.Empty)?Convert.DbNull:paramValue;
Reply

Use magic Report

1

Threads

60

Posts

37.00

Credits

Newbie

Rank: 1

Credits
37.00

 China

Post time: 2020-12-10 17:30:01
| Show all posts
You can execute the stored procedure if you get the value. You can set a breakpoint first to see if the value is obtained.
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-12-10 17:45:01
| Show all posts
cm.Parameters.Add(new SqlParameter("@usort",SqlDbType.VarChar,50));


Set breakpoint: unconditionally, always break, current value is 1
Reply

Use magic Report

6

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-12-10 18:00:01
| Show all posts
cm.Parameters["@usort"].Value=Request.Form["mydown1"];
Set breakpoint: unconditionally, always break, current value is 1
cm.Parameters["@utypename"].Value=Request.Form["mydown2"];
Set breakpoint: unconditionally, always interrupt, current value is 0

I don't know why
Reply

Use magic Report

0

Threads

1

Posts

0.00

Credits

Newbie

Rank: 1

Credits
0.00

 China

Post time: 2020-12-10 23:11:38
| Show all posts
I will also try
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