Page 279 - DCAP312_WEB_TECHNOLOGIES_II
P. 279

Unit 14: Debugging and Optimization



               DataField= “ProductName”                                                           Notes
               SortExpression= “ProductName”/>
                <asp:BoundField HeaderText= “QuantityPerUnit”
               DataField= “QuantityPerUnit”
               SortExpression= “QuantityPerUnit”/>
                <asp:BoundField HeaderText= “UnitPrice” DataField= “UnitPrice”
               SortExpression= “UnitPrice”/>
               </Columns>
               </asp:GridView>
                <asp:SqlDataSource ID= “ProductsDataSource” Runat= “server”
                 SelectCommand= “SELECT DatePart(second, GetDate())
                 As Timestamp, *
                    FROM [Products] where CategoryID = @CategoryID”
                 ConnectionString= “<%$ ConnectionStrings:Northwind %>“
                 EnableCaching= “True” CacheDuration= “10”>
                 <SelectParameters>
                 <asp:ControlParameter Name= “CategoryID”
                 ControlID= “DropDownList1”
                 PropertyName= “SelectedValue”/>
                 </SelectParameters>
                 </asp:SqlDataSource>
                    <asp:SqlDataSource ID= “CategoriesDataSource” Runat= “server”
                    SelectCommand= “SELECT * FROM [Categories]”
                 ConnectionString= “<%$ConnectionStrings:Northwind %>“
                 EnableCaching= “True” CacheDuration= “10”/>
                 </form>
                 </body>
                 </html>
            In the preceding code, the connection string to the database is retrieved from the web.config
            file. The web.config file contains the following connectionStrings element:
                        <connectionStrings>
                              <add name= “Pubs”
                        connectionString= “server=localhost;database=Pubs;
                                 trusted_connection=true”/>
                               <add name= “Northwind”
                                 connectionString= “server=localhost;database=Pubs;
                                 trusted_connection=true”/>
                        </connectionStrings>
            Now that the required connection string is defined in the web.config file, the SqlDataSource
            control can use that connection string by using the following declaration:
               1.  <%$ ConnectionStrings:Northwind %>




                                             LOVELY PROFESSIONAL UNIVERSITY                                   273
   274   275   276   277   278   279   280   281   282   283   284