Thursday, March 3, 2011

Resources

Check back to this post often as it will be updated and improved over time.


Microsoft


http://msdn.microsoft.com/en-us/ - The Microsoft MSDN website. Provides articles, whitepapers, interviews, and sample code for software developers using Microsoft products.


http://www.asp.net/ - The Official ASP.NET website. Official site maintained by Microsoft with links to information, IBuySpy and other community sites and resources


http://www.microsoft.com/net/ - Microsoft .NET Framework website.


http://msdn.microsoft.com/en-us/vbasic/default - Visual Basic Developer Center


http://msdn.microsoft.com/en-us/vcsharp/default - Visual C# Developer Center


http://windowsclient.net/default.aspx - The Official Microsoft WPF and Windows Forms Site


https://www.dreamspark.com/default.aspx - Microsoft DreamSpark - Microsoft DreamSpark is a platform for downloading free softwares for students.




JavaScript and jQuery


http://jquery.com/ - jQuery - The Write Less, Do More, JavaScript Library




Online Communities


http://dreamincode.net/ - DreamInCode.net - Programming and Web Development Help

Databound DropDownLists

So you want to populate a DropDownList with values from a database, huh? Well, it is not incredibly hard. You can do it from the designer by hovering over the DropDownList and selecting "Choose Data Source..." from the smart tag. You can also do it from code like so:


  1.         <asp:DropDownList ID="DropDownList1" runat="server"
  2.            DataSourceID="SqlDataSource12" DataTextField="linkShortDesc"
  3.            DataValueField="linkShortDesc">
  4.         </asp:DropDownList>
  5.         <asp:SqlDataSource ID="SqlDataSource12" runat="server"
  6.            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
  7.             SelectCommand="SELECT [linkShortDesc] FROM [Links]"></asp:SqlDataSource>

As you can see from the code, we created a new ASP.NET SqlDataSource, provided our connection string and our query we wanted to run. In my case I'm returning a list of links from a table. Now, in our ASP.NET DropDownList code, we can specify a DataValueField and a DataSourceID. The DataSourceID is the ID of the data source we want to link to, and DataValueField is the name of the column we want to display in our drop down list.

Happy coding!

ASP.NET Menu Control

Navigation is nice. And so is implementing navigation easily. It is really cool that ASP.NET and Visual Studio will help us with this, with the Menu control.

In your toolbox, go to the "Navigation" tab and double click "Menu" on the list. This will add a new menu control to your page. The Menu control is easier to use in design mode, so switch to design mode.

If you hover over your menu control, the smart tag should appear (the little arrow usually to the right). It gives us some options (I won't list all of them here):

  • Auto format: This will open a dialog to quickly apply themes to your menu control. Go ahead, select one.
  • Views: (Static or Dynamic): Static view is where the links for your menu are always visible on the screen. Useful if you want something similar to a navigation bar at the top of the screen. Dynamic: allows for some fancy animations and other useful features. Useful if you want to preserve screen real-estate.
  • Edit Menu Items: This will open a dialog where you can add items to your menu. Root items will appear on the menu bar and children items will appear below their corresponding root items.
How to change the orientation of the menu control:

After you select your menu control, go to the properties page of Visual Studio and find "Orientation". It has two possibilities: Horizontal or Vertical. Just like you would think, Horizontal gives the menu control a horizontal orientation and vertical gives the menu control a vertical orientation.

To do this in code:

However, this can be accomplished through the code window. I will show you the code, and then explain it.

  1.  <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
  2.         <Items>
  3.             <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>
  4.             <asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
  5.             <asp:MenuItem Text="Contact Us" Value="Contact Us"></asp:MenuItem>
  6.             <asp:MenuItem Text="Services" Value="Services">
  7.                 <asp:MenuItem Text="I Break Code Blog" Value="I Break Code Blog"></asp:MenuItem>
  8.                 <asp:MenuItem Text="Open Source Software" Value="Open Source Software">
  9.                 </asp:MenuItem>
  10.             </asp:MenuItem>
  11.         </Items>
  12.  </asp:Menu>

Lines 1 and 13 define the region of code which will contain the ASP.NET Menu Control. The Menu Control is contained between the <asp:Menu> tag and the </asp:Menu> tag. If you notice, the <asp:Menu> tag has a few attributes associated with it in this example:

  • runat: Determines where an element is processed. 'Server' controls are processed before the website is sent to the browser.
  • Orientation: gets or sets the direction in which to render the Menu control.
Lines 2 and 11 define the region of code where the ASP.NET Menu Control items are defined. The Menu Control items are contained between the <Items> tag and the </Items> tag.

The individual ASP.NET Menu Control items are defined with the <asp:MenuItem> and </asp:MenuItem> tags.

If you look at this code: <asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
you will see the attributes 'Text' and 'Value':
  • The 'Text' attribute sets the text displayed in the ASP.NET Menu Control
  • The 'Value' attribute sets the text associated with the Menu Control that will not be displayed on the ASP.NET Menu Control
External Resources Related To: ASP.NET Menu Control

Master Pages, Content Pages and Content Place Holders

Master Pages save a web developer a lot of design hassle when building web applications (or websites). Essentially, they are a template for pages within your web application.

To create a master page in Visual Studio, click the 'Website' menu button and then click 'Add New Item...'. When the Add New Item dialog appears, choose 'Master Page' from the list and then give it a name. Then click 'Add'.

Visual Studio will create a file that looks like this:

  1. <%@ Master Language="VB" CodeFile="myMasterPage.master.vb" Inherits="myMasterPage" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title></title>
  6.     <asp:ContentPlaceHolder id="head" runat="server">
  7.     </asp:ContentPlaceHolder>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.         <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
  13.        
  14.         </asp:ContentPlaceHolder>
  15.     </div>
  16.     </form>
  17. </body>
  18. </

If you look at the code, you will see content placeholder controls. These are used by content pages, which are derived from your master pages. Master pages are the page template, and content pages contain the content of your web page.

Content place holders define areas in your master page where the content is replaceable inside your content pages.

To create a content page, go to the Solution Explorer within Visual Studio, and right click on your master page and choose "Add Content Page". This will create a new content page that is linked to the master page you selected. This means that all the content placeholders you created in your master page will appear in your content page.

Note: When dealing with content pages, you can only put content in a content placeholder.

The new content page should look similar to this:

  1. <%@ Page Title="" Language="VB" MasterPageFile="~/myMasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2. <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    Header content goes here
  3. </asp:Content>
  4. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    Our content goes here.
  5. </asp:Content>
I Break Code Where code gets done.
ASP.NET | HTML | SQL Server | VB.NET | Request A Topic |