|
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",""));
} |
|