Banner Ad

Sunday, December 21, 2014

An easy way to construct the Connection String in ASP.Net

By Francis   Posted at   7:26 AM   Connection String 2 comments

Connection strings are necessary when you want to interact with any databases like SQL Server, MSAccess etc. Most probably if you are using ADO.Net Concepts to interact with Database then you can aware about the connection string. In this article I am going to share how it can be easily constructed.

 

Step 1:

Open Visual Studio and create sample web form application.

 

Step 2:

Switch over to “Design Mode” and in the tool box, just drag and drop a “Gridview” control in to the web form.

DesignMode-1

 

Step 3:

Select “New Data Source”.

DesignMode-2

Step 4:

In the “Data Source Configuration Wizard”, select your database click “OK”.

Datasource-1

Step 5:

In the next step of the wizard, Click “New Connection”.

Datasource-2

Step 6:

It will provide a pop-up dialog box to select “Data Source”, in that select “Data Source” and select data provider from “Data Provider” dropdown list, then click “Continue”.

Datasource-3

Step 7:

In “Add Connection” modal dialog, select your “Server Name” (if not available, first click “Refresh” button, still it not available type your “SQL Server Name” manually on it).

You can either use, “Windows Authentication” or “SQL Server Authentication” to login to your SQL Server.

As a next step, select your database, that is available on your SQL Server. Finally, click “Test Connection”, to check whether the connection is established successfully or not.

Datasource-4

 

Datasource-5

Step 8:

As a final step, you will get the Connection string, which can be used on your web/windows application to connect the DB.

Datasource-6

Happy Coding!

Saturday, December 20, 2014

ASP.Net MVC – Create Custom HTML Helpers

By Francis   Posted at   11:52 AM   Razor No comments
Html Helpers are classes that helps to render HTML controls in Views. We can also create our own HTML Helpers. In this post, I’m going to explain how to create a simple Custom HTML Helper. The main purpose creating custom HTML helper is reuseability.

Step 1:
          Create a static class and add method to it like below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVCTutorial
{
    public static class CustomHTMLHelper
    {
        public static MvcHtmlString ImageLink(string action, string controller, string imgageURL)
        {
            // Create a link with an image
            return MvcHtmlString.Create(String.Format("<a href=\"{1}\\{0}\"> <img src=\"{2}\" /></a>", action, controller, imgageURL));
        }
    }
}

     
Step 2:
          Access the custom helper class in a View.
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Sample</title>
</head>
<body>
    <div>
        @CustomHTMLHelper.ImageLink("Home","Account","your image url")
    </div>
</body>
</html>


The helper class is static, since it can be called in a easy manner also handy.
Happy coding!

Tuesday, December 9, 2014

Design Pattern - An Introduction

By Francis   Posted at   5:08 PM   Design Pattern No comments

                                  Few weeks ago, I commit to take an session about design pattern in my organization. As a matter of fact, I’m not a big fan of design pattern. However, I began dwell with design pattern, I found interesting on it. So I decided to write some posts on it. In this post, I just give an introduction about design pattern.
So what is design pattern?

                                 Design Pattern are conceived by the 4 people who wrote the book "Design Patterns: Elements of Reusable Object-Oriented Software ".  Design pattern is a proven ways to solve the particular problem while arising often writing software programs. Those problems are frequently encountered by the programmers, most probably when design the software.  So there is no reinvent the well again. There are 23 solutions predefined by the above authors. Each problem has its own name also.
The ultimate goal:
There is no reinvent of solution for the 23 problems. Also the main benefit is maintainability of software. If you want to change something in the existing system it is so easy. The above are the main benefits of design pattern. These 23 design patterns are called Gang Of Four in general.
                           They are categorized into 3 types. They are: 1. Structural Pattern 2. Creational Pattern 3. Behavioral Patterns

The category name itself enough to explain, the purpose of each pattern. For example, Creational patterns are talk about the object creation. At the same time structural pattern described about code structure. Below are the 23 design patterns.

 

Creational Patterns:

  1. Abstract Factory
  2. Singleton Pattern
  3. Builder Pattern
  4. Factory Method Pattern
  5. Prototype Pattern

 

Structural Patterns:

  1. Flyweight Pattern
  2. Proxy Pattern
  3. Adapter Pattern
  4. Bridge Pattern
  5. Facade Pattern
  6. Composite Pattern
  7. Decorator Pattern
  • Behavioral Patterns:
    1. Chain of Responsibility
    2. Observer Pattern
    3. Command Pattern
    4. Interpreter Pattern
    5. Iterator Pattern
    6. Visitor Pattern
    7. Template Pattern
    8. Strategy Pattern
    9. Memento Pattern
    10. Mediator Pattern
    11. State Pattern
Connect with Us