Database implementation: Add two tables, table 1, pingpai, table 2, and type. The specific database implementation depends on your understanding:
Page code:
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
</ASP: scriptmanager>
<Asp: updatepanel runat = "server">
<Contenttemplate>
<Asp: dropdownlist id = "dropdownlist1" runat = "server" onselectedindexchanged = "dropdownlist1_selectedindexchanged"
Width = "200">
</ASP: dropdownlist>
<Asp: dropdownlist id = "dropdownlist2" runat = "server" width = "200">
</ASP: dropdownlist>
</Contenttemplate>
</ASP: updatepanel>
// The above code implements the refreshing effect of AJAX
Main program code:
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Binddrop ();
}
}
Private void binddrop ()
{
// Bind data to the drop-down list
String sqlstr = "select * From pingpai ";
Datatable dt = database. gettable (sqlstr );
Dropdownlist1.datatextfield = "pingpai"; // set the words displayed in the list
Dropdownlist1.datavaluefield = "typeid"; // set the fields obtained after the list is submitted. You can hide the bound data.
Dropdownlist1.datasource = DT. defaultview;
Dropdownlist1.databind ();
Dropdownlist1.items. insert (0, new listitem ("select the car brand", ""); // add content to the first item, focusing on adding after binding
Dropdownlist2.items. insert (0, new listitem ("select the car brand model", ""); // add content to the first item, focusing on adding after binding
}
Protected void dropdownlistincluselectedindexchanged (Object sender, eventargs E)
{
Int typeid = convert. toint32 (dropdownlist1.selectedvalue); // After the page is loaded, dropdownlist1.datavaluefield hides the bound data and then queries the data to be displayed in dropdownlist2 based on it.
String sqlstr = "select * from type where typeid = '" + typeid + "'";
Datatable dt = database. gettable (sqlstr );
Dropdownlist2.datatextfield = "type"; // set the data displayed in the dropdownlist1 event selectedindexchanged dropdownlist2 list
Dropdownlist2.datasource = DT. defaultview;
Dropdownlist2.databind ();;
}