Implementation of Brushless newest cascade in ASP. NET

Source: Internet
Author: User

Recently, I was working on a device Repair System for the school. Due to the limited level, I seldom used Ajax knowledge when I was working on projects. To achieve better results, I checked the relevant materials, refer to the online tutorial to write the followingProgram, Please correct me more.

Development Environment configuration: Visual Studio 2008 SQL Server 2008

Source code: brushless newest Cascade

1. Create a Test Database

Two tables are used, one is department, and the other is usedepart.

Table: Department

Table: usedepart

2. Create a New myclass class

Public class myclass {public dataset getlist (string table, string where) {string connstr = configurationmanager. connectionstrings ["conn"]. connectionstring; using (sqlconnection conn = new sqlconnection (connstr) {stringbuilder strsql = new stringbuilder (); strsql. append ("select * from "). append (table); If (! String. isnullorempty (where) {strsql. append ("where "). append (where);} using (sqlcommand cmd = new sqlcommand (strsql. tostring (), Conn) {Conn. open (); dataset DS = new dataset (); sqldataadapter da = new sqldataadapter (); DA. selectcommand = cmd; DA. fill (DS, "ds"); Return DS ;}}}}

3. default. aspx pageCodeJavaScript code

<SCRIPT type = "text/JavaScript"> $ (function () {$ ("# <% = ddldepartment. clientid %> "). change (function () {$ ("# ddlusedepart "). load ("loadusedepart. aspx? Indepartid = "+ $ (" # "+" <% = ddldepartment. clientid %> "+" option: Selected "). val () ;}); </SCRIPT>

4. loadusedepart. aspx background code

Protected void page_load (Object sender, eventargs e) {int ID; If (Int. tryparse (request. params ["indepartid"]. tostring (), Out ID) {response. write (getusedepart (ID); response. end () ;}} private string getusedepart (int id) {stringbuilder sb = new stringbuilder (); dataset DS = new myclass (). getlist ("usedepart", "departid =" + id); If (Ds. tables. count> 0) {for (INT I = 0; I <Ds. tables [0]. rows. count; I ++) {sb. append ("<option value = '" + Ds. tables [0]. rows [I] ["ID"]. tostring () + "'>" + Ds. tables [0]. rows [I] ["name"]. tostring () + "</option>") ;}} return sb. tostring ();}

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.