Three-Level linkage in ASP pages to load data

Source: Internet
Author: User

ASP page:

Card category: <asp: dropdownlist id = "dropdownlist_cardtype1" runat = "server" autopostback = "true" onselectedindexchanged = "inline" datatextfield = "typename" datavaluefield = "typenum"> </ASP: dropdownlist> <asp: dropdownlist id = "dropdownlist_cardtype2" runat = "server" autopostback = "true" onselectedindexchanged = "inline" datatextfield = "typename" datavaluefield = "typenum"> </ASP: dropdownlist> <asp: dropdownlist id = "dropdownlist_cardtype3" runat = "server" datatextfield = "typename" datavaluefield = "typenum"> </ASP: dropdownlist>

Set autopostback = "true" in the first and second drop-down boxes"

C # background code:

# Region _____________ load data _____ card type ____________ // card type string typesql = "select distinct typenum, typename from tbl_cardtypenew where typelevel = '1'"; dataset ds2 = dbfhkhelper. querydb (typesql); If (! Ispostback) {If (ds2.tables [0]. rows. count> 0) {datatable Table1 = new datatable (); table1.columns. add ("typenum"); table1.columns. add ("typename"); datarow drnew = table1.newrow (); drnew ["typename"] = "-All-"; drnew ["typenum"] = "-All -"; table1.rows. add (drnew); table1.merge (ds2.tables [0]); dropdownlist_cardtype1.datasource = Table1; dropdownlist_cardtype1.databind (); rows = 0 ;}// the second type of able Table2 = new datatable (); table2.columns. add ("typenum"); table2.columns. add ("typename"); datarow drnew2 = table2.newrow (); drnew2 ["typename"] = "-All-"; drnew2 ["typenum"] = "-All -"; table2.rows. add (drnew2); dropdownlist_cardtype2.datasource = Table2; dropdownlist_cardtype2.databind (); frequency = 0; // The third type: dropdownlist_cardtype3.datasource = Table2; frequency (); frequency = 0 ;} # endregion _____________ load data _________________

Select an event in the first drop-down box and load the data in the second drop-down box.

C # The Code is as follows:

# After region selects the level 1 category, load the Level 2 category protected void dropdownlist_cardtype1_selectedindexchanged (Object sender, eventargs e) {dropdownlist_cardtype2.datasource = NULL; dropdownlist_cardtype3.datasource = NULL; // able Table2 = new datatable (); table2.columns. add ("typenum"); table2.columns. add ("typename"); datarow drnew2 = table2.newrow (); drnew2 ["typename"] = "-All-"; drnew2 ["typenum"] = "-All -"; tabl E2.rows. Add (drnew2); dropdownlist_cardtype3.datasource = Table2; dropdownlist_cardtype3.databind (); bytes = 0; string type1 = bytes (); // 01-type name if (type1! = "-All-") {// query the second-level card category string querysql = "select typenum, typename from tbl_cardtypenew where uplnum = '"+ type1 +"' and typelevel = '2' "; dataset ds2 = dbfhkhelper. querydb (querysql); If (ds2.tables [0]. rows. count> 0) {datatable Table1 = new datatable (); table1.columns. add ("typenum"); table1.columns. add ("typename"); datarow drnew = table1.newrow (); drnew ["typename"] = "-All-"; drnew ["typenum"] = "-All -"; table1.rows. add (drnew); table1.merge (ds2.tables [0]); dropdownlist_cardtype2.datasource = Table1; dropdownlist_cardtype2.databind (); dropdownlist_cardtype2.selectedindex = 0 ;} else {// second-level card category datatable table3 = new datatable (); table3.columns. add ("typenum"); table3.columns. add ("typename"); datarow drnew3 = table3.newrow (); drnew3 ["typename"] = "-All-"; drnew3 ["typenum"] = "-All -"; table3.rows. add (drnew3); dropdownlist_cardtype2.datasource = table3; dropdownlist_cardtype2.databind (); Category = 0 ;}} else {// datatable table3 = new datatable (); table3.columns. add ("typenum"); table3.columns. add ("typename"); datarow drnew3 = table3.newrow (); drnew3 ["typename"] = "-All-"; drnew3 ["typenum"] = "-All -"; table3.rows. add (drnew3); dropdownlist_cardtype2.datasource = table3; dropdownlist_cardtype2.databind (); dropdownlist_cardtype2.selectedindex = 0 ;}# endregion select the level 1 category and load the Level 2 Category

Select an event in the second drop-down box and load the data in the third drop-down box:

# After region selects the second-level card category, load the third-level card category protected void dropdownlist_cardtype2_selectedindexchanged (Object sender, eventargs e) {dropdownlist_cardtype3.datasource = NULL; string type2 = callback (); // 0102-type name if (type2! = "-All-") {// query the string querysql = "select typenum, typename from tbl_cardtypenew where uplnum = '"+ type2 +"' and typelevel = '3' "; dataset ds2 = dbfhkhelper. querydb (querysql); If (ds2.tables [0]. rows. count> 0) {datatable Table1 = new datatable (); table1.columns. add ("typenum"); table1.columns. add ("typename"); datarow drnew = table1.newrow (); drnew ["typename"] = "-All-"; drnew ["typenum"] = "-All -"; table1.rows. add (drnew); table1.merge (ds2.tables [0]); dropdownlist_cardtype3.datasource = Table1; dropdownlist_cardtype3.databind (); dropdownlist_cardtype3.selectedindex = 0 ;} else {// third-level card category datatable table3 = new datatable (); table3.columns. add ("typenum"); table3.columns. add ("typename"); datarow drnew3 = table3.newrow (); drnew3 ["typename"] = "-All-"; drnew3 ["typenum"] = "-All -"; table3.rows. add (drnew3); dropdownlist_cardtype3.datasource = table3; dropdownlist_cardtype3.databind (); Category = 0 ;}} else {// able table3 = new datatable (); table3.columns. add ("typenum"); table3.columns. add ("typename"); datarow drnew3 = table3.newrow (); drnew3 ["typename"] = "-All-"; drnew3 ["typenum"] = "-All -"; table3.rows. add (drnew3); dropdownlist_cardtype3.datasource = table3; dropdownlist_cardtype3.databind (); dropdownlist_cardtype3.selectedindex = 0 ;}# endregion select Level 2 Category and load level 3 Category

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.