Talk about the usage of user controls: Simply put, the easiest way to get a user control is to change an ASPX file suffix to ASCX and turn <% @ page ...%> Page to the Control Directive. Specific For example: <% @ control language = "c #"%> // Note here <% @ Import namespace = "system.data"%> <% @ import namespace = "system.data.sqlclient"%>
Public void page_load (Object Source, Eventargs E) {if (! ispostback) {sqlConnection MyConnection; SqlCommand MyCommand; SQLDATAREADER MyReader; String SQL; String ConnStr;
SQL = "SELECT * from shippers"; connStr = configurationSettings.appsettings ["dsnnorthwind"];
MyConnection = New SqlConnection (connStr); MyConnection.Open ();
MyCommand = New SQLCOMMAND (SQL, MyConnection);
MyReader = myCommand.executeReader ();
While (MyReader.Read ()) ShipMethod.Items.Add (New ListItem (MyReader ["CompanyName"]. TOSTRING (), MyReader ["shipperid"]. toString ()));}} script>
Next is a question about the user control attribute: <% @ import namespace = "system.data"%> <% @ import namespace = "system.data.sqlclient"%>