Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Custom Pager in MVC Pagedlist

In this article I am going to explain how to customize the pager in MVC Pagedlist.

Description:
I want to show total number of records and number records are showing out of total records. Change the pagesize using dropdown.

Implementation:

Model
  public partial class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Nullable<int> Phone { get; set; }
        public Nullable<int> Salary { get; set; }
        public string Department { get; set; }
        public string ImagePath { get; set; }
        public string EmailId { get; set; }
    }

ASP.NET MVC : Change page size with dropdown

In this article I am going to explain how to change page size with dropdown in asp.net MVC.

Description:
I am using Pagedlist.mvc package for pagination. In previous article I have explained  .  Now I want to change/set page size using dropdown in foreach loop.

Implementation:
I want to display list of employees.

Model (Employee.cs)
    public partial class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Nullable<int> Phone { get; set; }
        public Nullable<int> Salary { get; set; }
        public string Department { get; set; }
        public string ImagePath { get; set; }
        public string EmailId { get; set; }
    }

Add controller
Now add an empty controller to project. Create action to fetch the data.

Complete code of controller

Asp.net : Convert base 64 string into image

In this article I am going to explain how to convert or save Base64 string as image in asp.net.

Description:
Recently I have got a requirement to implement digital signature functionality in application. To fulfill this requirement I have use Signature pad jquery. It is HTML5 canvas based. The signature file is created in base64 string. I want to save this base64 string as image in application.

Implementation:
You can download Signature pad script from here. Download Javascript and add reference to web form.

HTML Markup of webform

Asp.net : how to implement digital signature

In this article I am going to explain how to implement digital signature in asp.net application.

Description:
Recently I have got a requirement to implement digital signature functionality in application. To fulfill this requirement I have use Signature pad jquery. It is HTML5 canvas based.

Implementation:
You can download Signature pad script from here. Download Javascript and add reference to web form.

HTML Markup of webform

How to implement pagination in MVC application

In this article I am going to explain how to implement pagination in MVC application.

Description:
I am showing the employees information in foreach loop. I want to paginate the data. For pagination in MVC Pagedlist package is available. You can install this from Nuget package manager console. Run the below command:

Install-Package PagedList.Mvc

Implementation:
Model class of Employee (Employee.cs)

public partial class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Nullable<int> Phone { get; set; }
        public Nullable<int> Salary { get; set; }
        public string Department { get; set; }
        public string ImagePath { get; set; }
        public string EmailId { get; set; }
    }


Add controller
Get count of rows and columns from datatable in asp.net

Get count of rows and columns from datatable in asp.net

In this article I am going how to get count of rows and columns from datatable in asp.net.

Implementation:
I want to know how many rows and columns in datatable or dataset?

Syntax
C# code

int row = dt.Rows.Count;
int column = dt.Columns.Count;
//dataset row count
  int row = ds.Tables[0].Rows.Count;
  int column = ds.Tables[0].Columns.Count;

VB.net code

Dim row As Integer = dt.Rows.Count
Dim column As Integer = dt.Columns.Count
dataset row count
Dim row As Integer = ds.Tables(0).Rows.Count
Dim column As Integer = ds.Tables(0).Columns.Count

Example:
HTML Markup of webform

Asp.net Gridview : Replace null or empty value with default message

In this article I am going to explain how to replace null or empty value with default message such as “-NA-“or “Data not available” in asp.net Gridview.

Description:
I am showing list of Employees in gridview data control. Some of columns are empty. I want to show a default message “-NA-“instead of empty column.

  
Implementation:

Different approaches to change Gridview row color on mousehover in asp.net

In this article I am going to explain different approaches to change Gridview row color on mousehover in asp.net.

Description:
I am showing employees detail in Gridview data control. I want to change the color of row on mousehover.


Implementation:
We have many approaches to change the row color on mousehover code behind, through CSS and javascript.

HTML Markup of webform:

Apply and remove CSS class or style in asp.net code behind

In this article I am going to explain how to apply and remove CSS class or style in asp.net code behind.

Description:
I want to apply and remove CSS class or style code behind.

Implementation:
I have add 2 buttons to webform, one to apply style and 2nd to remove style or class.

Complete HTML Markup:

Asp.net Gridview: Change row color on mousehover

In this article I am going to explain how to change Gridview row color on mousehover in asp.net.

Description:
I am showing employees detail in Gridview data control. I want to change the color of row on mousehover.


Implementation:
We have many approaches to change the row color on mousehover code behind, through CSS and javascript.

HTML Markup of webform:

Asp.net : Live preview of Text typed in textbox using Jquery

In this article I am going to explain how to show live preview of text typed/enter in textbox using jquery.

Description:
I want to show the preview of text while type in textbox. I am using jquery

Implementation:
I have create Jquery function. On keyup function preview will be show.

How to pass parameter to RDLC report in MVC

In this article I am going to explain how to create and pass parameter to RDLC report in MVC application.

Description:
I want to show report of State population and users can filter the search for particular state. I am going to use RDLC report to create and Reportviewer to show report.

Implementation:
Follow the below given steps to create RDLC report in MVC application:

MVC : Create RDLC report

In this article I am going to explain how to create RDLC report in MVC application

Description:
I want to show report of State population. I am going to use RDLC report to create and Reportviewer to show report.

Implementation:
Follow the below given steps to create RDLC report in MVC application:

Javascript : Show and hide div

In this article I am going to explain how to show and hide DIV using Javascript.

Description:
I want to hide and show the div on button click using Javascript.

Implementation:

Here is the example:

Complete HTML markup:

Real time preview of Html code textarea in asp.net using jquery

In this article I am going to explain how to see real time preview of Html code from textarea in asp.net using jquery.


Description:
I want to display real time preview of HTML code/text entered in text area. I am using Jquery to implement this.

Implementation:
Create a jquery Keyup function.

Asp.net : How to remove special character’s from string

In this article I am going to explain how to remove special character’s from string or  text typed/entered in Textbox in asp.net.

Description:
I want to remove special characters from text typed/entered in Textbox or string using RegularExpressions.


Implementation:

Complete Html markup of webform:

Avoid special characters and space to enter in textbox using Jquery

In this article I am going to explain how to avoid special characters and space to enter (type) in textbox using Jquery

Description:
In application I am validating username. I want to avoid entering space and special characters in username. I am going to do this using jquery.

Implementation:
We have to create Keypress method. Here is jquery code that I am using:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
            <script type="text/javascript">
                $(document).ready(function () {
                    // restrict special characters
                    $('#TextBox1').keypress(function (key) {
                        var regexpns = new RegExp("^[a-zA-Z0-9]+$");
                        var key = String.fromCharCode(event.charCode ? event.which : event.charCode);
                        if (!regexpns.test(key)) {
                            event.preventDefault();
                            document.getElementById("message").style.display = 'block';
                            return false;                       
                        }
                        else
                        {
                            document.getElementById("message").style.display = 'none';
                        }
                    });
                });
            </script>

Complete HTML Markup of webform:

Asp.net : Display tooltip in Gridview column on mouseover

In this article I am going to explain how to display tooltip in Gridview column on mouseover in asp.net. 

Description:
I am displaying employee’s information in Gridview and want to display each column data when placed mouse on column. We have 2 options 1st write  code on RowDataBound event of Gridview and 2nd use the label control’s tooltip property.

Implementation:
Method 1:

Complete source of webform

How to show tooltip on entire Gridview row hover in asp.net

In this article I am going to explain how to show tooltip on entire Gridview row mouse hover in asp.net.


Description:
I am displaying employees information in Gridview and want to display name & phone no. when mouse is hovered on row. To fulfill this requirement we have write code on RowDataBound event of Gridview.

Implementation: 

Complete source of webform

Asp.net Adrotator : Display ads without page refresh

In this article I am going to explain how to show ads without page refresh using Sql server database in asp.net Adrotator control.

Description:
Adrotator control is used to show custom Ads (advertisements) on asp.net build websites. When users click on any ad they will be redirect to link assign for that. We can use both Xml and database as data source. Xml and database table must have following properties and columns: ImageUrl, NavigateUrl, AlternateText, Impressions, Keyword, Width and Height.

Implementations:
In this example I am going to use sql server database as adrotator data source. I have create a table Ads and insert some dummy records into it. To show ads without page refresh I am going to use Updatepanel and Timer control.

Asp.net Adrotator : Display ads without page refresh


Complete source of webform