Add template column in a grid dynamically

METHOD WHERE THE TEMPLATE COLUMNS ARE ADDED DYNAMICALLY.
IT USES THE CLASS  DataGridTemplete
 Dim count As Integer
 Dim oDataRows() As DataRow
 Dim oDataRow As DataRow
 Public Sub AddColumnToConfig()
            Dim roles As New rolesDbSql
            count = 0
            oDataRows = roles.GETROW().Tables(0).Select
            For Each oDataRow In oDataRows
                If Not oDataRow("HeaderImageUrl").GetType.Name = "DBNull" And Not oDataRow("HeaderImageUrl").GetType.Name = "" Then
                    Dim dgc As TemplateColumn = New TemplateColumn
                    If oDataRow("roleid") = oDataRow("roletype") Then
                        dgc.ItemStyle.BackColor = Color.FromName("#4292C6")
                        dgc.ItemStyle.HorizontalAlign = HorizontalAlign.Center
                        dgc.HeaderTemplate = New DataGridTemplete(ListItemType.Header, oDataRow("RoleDescription").ToString(), oDataRow("HeaderImageUrl").ToString(), oDataRow("rolename").ToString().Replace(" ", ""))
                        dgc.ItemTemplate = New DataGridTemplete(ListItemType.Item, oDataRow("RoleDescription").ToString(), oDataRow("HeaderImageUrl").ToString(), oDataRow("rolename").ToString().Replace(" ", ""))
                        UsersGrid.Columns.Add(dgc)
                    Else
                        dgc.ItemStyle.BackColor = Color.FromName("#DBEAF5")
                        dgc.ItemStyle.HorizontalAlign = HorizontalAlign.Center
                        dgc.HeaderTemplate = New DataGridTemplete(ListItemType.Header, oDataRow("RoleDescription").ToString(), oDataRow("HeaderImageUrl").ToString(), oDataRow("rolename").ToString().Replace(" ", ""))
                        dgc.ItemTemplate = New DataGridTemplete(ListItemType.Item, oDataRow("RoleDescription").ToString(), oDataRow("HeaderImageUrl").ToString(), oDataRow("rolename").ToString().Replace(" ", ""))
                        UsersGrid.Columns.Add(dgc)//USERSGRID IS THE DATAGRID ID
                    End If



                End If

                count = count + 1
            Next
        End Sub

-----------------------------------------------------------------------------------------------------------
CLASS DataGridTemplete

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Namespace FileOn
    'A customized class for displaying the Template Column

    Public Class DataGridTemplete
        Implements ITemplate
        'A variable to hold the type of ListItemType.
        Dim _templateType As ListItemType
        'A variable to hold the column name.
        Dim _columnName As String
        'A variable to hold the url for the header image
        Dim _Url As String
        'Id for the checkbox
        Dim chkId As String
        'Constructor where we define the template type and column name.
        Public Sub New(ByVal type As ListItemType, ByVal colname As String, ByVal url As String, ByVal id As String)
            'Stores the template type.
            _templateType = type

            'Stores the column name.
            _columnName = colname
            _Url = url
            chkId = id
        End Sub

        Private Sub ITemplate_InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
            Select Case _templateType
                Case ListItemType.Header
                    'Creates a new Image control and add it to the container.

                    Dim img As Image = New Image
                    'Alocate the image url
                    img.ImageUrl = _Url
                    'Assigns the image of the column in the lable.
                    container.Controls.Add(img)
                    'Adds the newly created label control to the container.
                    Exit Select
                Case ListItemType.Item                    'Creates a new text box control and add it to the container.
                    Dim chk As New CheckBox()
                    'Allocates the new text box object.                    AddHandler chk.DataBinding, AddressOf Me.chk_DataBinding
                    'Attaches the data binding event.
                    chk.ID = "chk" & chkId.ToString()                    chk.Enabled = False
                    chk.ToolTip = _columnName
                    container.Controls.Add(chk)
                    'Adds the newly created textbox to the container.
                    Exit Select
                Case ListItemType.EditItem                    'As, I am not using any EditItem, I didnot added any code here.
                    Exit Select
                Case ListItemType.Footer                    Dim chkColumn As New CheckBox()
                    chkColumn.ID = "Chk" & _columnName
                    container.Controls.Add(chkColumn)
                    Exit Select
            End Select
        End Sub        Private Sub chk_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
            Dim chk As CheckBox = DirectCast(sender, CheckBox)
            Dim container As DataGridItem = DirectCast(chk.NamingContainer, DataGridItem)
        End Sub    End ClassEnd Namespace


Date difference in javascript

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function displayDate()
{
var days = 0;
var difference = 0;
var today=new Date('02/21/1021'); //CONVERT STRING TO DATE
var today1=new Date('02/18/1021'); //CONVERT STRING TO DATE
difference = today1- today;
days = Math.round(difference/(1000*60*60*24));//DIFFERENCE
alert(days)
}
</script>
</head>
<body>

<h1>My First Web Page</h1>
<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>

Refresh or click

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{

    protected override void OnPreRender(EventArgs e)
    {
        ViewState["update"] = Session["update"];
    }
    void page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) // If page loads for first time
        {
            // Assign the Session["update"] with unique value
            Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
            //=============== Page load code =========================
            //============== End of Page load code ===================
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Session["update"].ToString() == ViewState["update"].ToString())
        {
            //=============== On click event code =========================

            lblDisplayAddedName.Text = txtName.Text;

            //=============== End of On click event code ==================

            // After the event/ method, again update the session

            Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
        }
        else // If Page Refreshed
        {
            // Do nothing
        }
    }
}