-->

Sunday, October 27, 2013

Exploring the visual studio 2012 IDE : Part-1

Introduction

Visual Studio 2012 provides an IDE to web developers, which is full of toolbars and windows. The windows are dockable, which allows to rearrange them on the IDE as per your requirements. The IDE can also be used for detecting and correcting the errors in your application. The following are the different parts of the visual studio 2012 IDE

  • Start Page
  • Menu Bar 
  • Toolbars 
  • Toolbox
  • The code Editor Window 
  • The Solution Explorer Window
  • The Property Window
  • The Object Browse Window
  • The Class View Window
  • The Server Explorer Window
  • The CSS Style Manager Window
  • The Output Window
  • The Task List Window
  • The Error List Window
  • The Command Window
  • The Dynamic Help Window

Start Page

When you open Visual Studio 2012, the very first window displayed is the Start Page.

 Visual Studio 2012, the very first window displayed is the Start Page

The Recent Projects/WebSites pane displays few projects/WebSites which you have created recently. The Start Page allows you to select from the most recent projects/WebSites on which you have recently worked. The following panes are displayed on the Start Page:
Recent Projects/WebSites : Displays a list of the most recent projects / websites you opened with visual studio, as shown in above figure . You can open the projects by clicking on the Hyperlink having the project's name. At the bottom of the Recent Projects pane two CheckBox are there first one for close page after project load and second one for Show page on startup.

Start : At the Above of the Recent Projects pane , you can see three links - one is for opening an existing project and the other for creating a new project and other for connecting to Team foundation server.

Getting Started: Contains links to various programming tasks in the product's documentation such as Manage your project in the cloud, Learning Resources etc.

Menu Bar

The Menu Bar of the Visual Studio IDE provides different menus for different Visual Studio commands

Menu bar in Visual studio 2012

Most of the menus are displayed as toolbars. Further, if you observe , not all options are available at all times. This is because the options that cannot be applied to the current state of the IDE are made either invisible or disable. For example, when you design the form, the Edit menu bar is quite short; however , when you perform the edit operation, it is quite lengthy.

ToolBars

Toolbars are shortcuts to the most frequently performed actions. You can fin the same commands in menus, but these shortcuts of toolbars are much faster to use than menus. You will find several common toolbars on the Visual Studio IDE, such as standard , layout , formatting , Debug, and Image Editor etc.

ToolBars in visual studio 2012

You can also build your own custom toolbars. Visual Studio displays the toolbars according to the selected object.

Saturday, October 26, 2013

How to Get Selected Fields from List Using LINQ: C#

When we bind a list with a control like datagridview, comboBox or listbox, then it will bind all the fields related to list. I have created a list of student with multiple fields i.e. Name, age, city and DOB. Now in this article I will bind only name and age of this list to a Datagridview.

To get selected fields, syntax of LINQ query will be:
var variable = from tempVar in list
select new
{
   tempVar.Field1,
   tempVar.Field2
};

Now in our case of Student class the records should be selected through the following C# line of code:
var selectedFields = from s in stuList
select new
{
s.Name,
s.Age
};
dataGridView1.DataSource = selectedFields.ToList();

In the last line of code, it will bind the list to gridview and show only name and age of the students like in following image:

Get selected fields in LINQ: C# windows forms
If all the LINQ methods are not showing in your program then sure about the namespace in your code file i.e. System. Linq;

See Also: How to Bind DataGridView with DataSet

How to Bind DataGridView to List Of Items: C#

Datagridview is the common control to bind our records in windows forms. I have bound this datagridview to dataset and in this article I will bind a list of student class’s data. I will use the same student class as in my previous post.

Drag-n-Drop a DataGridView on the form and write the following C# line of code in the constructor of the form.
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = stuList;
}

Before running the project, just sure that you have inserted some items in the stuList. To insert some records we can use an in-built Add function of the list. Write the following code to insert records:
stuList.Add(new Student() { Name = "Jacob", Age = 29, City = "London", Dob = new DateTime(1983, 5, 26) });
stuList.Add(new Student() { Name = "Zulia", Age = 31, City = "London", Dob = new DateTime(1981, 5, 26) });
stuList.Add(new Student() { Name = "Brandon", Age = 35, City = "London", Dob = new DateTime(1978, 5, 26) });

The record insertion should be done before the above binding. Run the project and the datagridview will be shown with these three records. The image shown the records in datagridview:

Friday, October 25, 2013

ASP.NET: Programmatically change CheckBoxList Border style

Lets take an simple Example

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.BorderStyle = BorderStyle.Dashed;
     
       
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        CheckBoxList1.BorderStyle = BorderStyle.Dotted;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CHANGE BORDER STYLE PROGRAMMATICALLY</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="24px" Width="208px">
        <asp:ListItem>ASP.NET CONTROLS</asp:ListItem>
        <asp:ListItem>JAVA CONTROLS</asp:ListItem>
        <asp:ListItem>TURBO CONTROLS</asp:ListItem>
        <asp:ListItem>PYTHON CONTROL</asp:ListItem>
    </asp:CheckBoxList>
    <div>
   
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="DASHED BORDER STYLE" Width="178px" />
   
        <br />
        <br />
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click"
            Text="DOTTED BORDER STYLE" Width="178px" />
   
    </div>
    </form>
</body>

</html>
Output

ASP.NET: Example of Programmatically change CheckBoxList Border color

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.BorderColor = System.Drawing.Color.Red;
        CheckBoxList1.BorderStyle = BorderStyle.Dashed;
        CheckBoxList1.BorderWidth = int.Parse("3");
       
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to change border color of the CheckBoxList Border color </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem>C++ Tutorial</asp:ListItem>
            <asp:ListItem>Java Tutorial</asp:ListItem>
            <asp:ListItem>ASP.NET Tutorial</asp:ListItem>
            <asp:ListItem>Turbo C Tutorial</asp:ListItem>
        </asp:CheckBoxList>
        <br />

        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Change" />
        <br />
        <br />
    </div>
    </form>
</body>

</html>
Output
ASP.NET: Example of Programmatically change CheckBoxList Border color

Difference between ASP.NET and ASP.NET AJAX

ASP.NET

 is a web development model, which is used to deliver interactive, data-driven Web application over the internet. It also consists of a large number of controls, such as a text boxes, button and labels for assembling , configuring, and manipulating code to create hyper Text Markup Language (HTML) pages. You can create ASP.NET application using any CLR compliant language such as Visual basic, C#, Visual c++ and j#. The main features of ASP.NET are as follows.

Better Performance – When you request a Web page for the first time after compiling ASP.NET code, the CLR complies the code and stores the cached copy of the result. Now, for any subsequent calls to the same pag, the cached copy of the result is retrieved instead of going back to the server.

Improved security –ASP.NET has four different methods of authentication:
1. Forms—Allows the ASP.NET application to use its own custom business logic for authentication.
2. Windows—Checks the identity of user against the Windows user accounts that are stored on the web Server. If the credentials of a user match with that of a Windows user account, then the user is authenticated.

Greater Scalability- The session states in ASP.NET are maintained in a separate process on a different machine or database. This enables cross-server sessions to occurs, solving the problem of Web forms when more web servers need to be added as the traffic grows.

Cookie-less Sessions—ASP.NET stores the session state even when the cookies in a Web Browser are disabled. In such a case, the session ID is passed as a part of the Uniform Resource Locator (URL).

Ajax,

 formerly code named as Atlas, is an extension of ASP.NET for developing and implementing AJAX functionality. ASP.NET AJAX Includes both client-side and server-side components that allow the developers to create Web application that are capable to update the data on a website without a complete reload of the page

The following are the advantages of using AJAX:
Asynchronous – Enable asynchronous calls to the web server without making the users wait for the data.

The minimal transfer of the data –Helps in sending only a part of the modified data to the web server minimizing the network traffic and performing the operations quicker. This feature is useful in sites where restricted pipes are allowed for data transfer resulting in improved network performance.

Minimal processing on the web server – Minimizes the processing on the web server as only the necessary data needs to be sent. Now, the server is not required to send a full page back to the server. 

ASP.NET: Programmatically change CheckBoxList Background Color

In previous example we already explain How to use CheckBoxList Control. If you want to change BackGround color on OnIndex change method then use this algorithm.
Step-1 : Add item to the CheckBox List using Show smart tag
Step-2 : Handle SelectedIndexChanged Event
Step-3 : If you want to change  BackGorgound color of the CheckBox List according to CheckBoxList Item then don't use System color enumeration.
Step-4 : Add Style Attribute in every selected item of CheckBoxList.

Complete Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (ListItem  item in CheckBoxList1.Items)
        {
            if (item .Selected)
            {
                CheckBoxList1.Attributes.Add("Style", "BackGround-color:" + CheckBoxList1.SelectedItem.Text); 
            }
        }
       
       
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change CheckBoxList BackGround Color</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
            <asp:ListItem>Red</asp:ListItem>
            <asp:ListItem>Green</asp:ListItem>
            <asp:ListItem>Yellow</asp:ListItem>
        </asp:CheckBoxList>
   
    </div>
    </form>
</body>

</html>
   Output
ASP.NET: Programmatically change CheckBoxList Background Color

ASP.NET: Programmatically change CheckBoxList Background Color

ASP.NET: Programmatically change CheckBoxList Background Color

© Copyright 2013 Computer Programming | All Right Reserved