OnItemCommand is not fired ListView C#, ASP.NET

I worked in ListView. And i faced one issue with OnItemCommand. There is link button, on click this button OnItemCommand event shoud fire. But it is not working. Because there is no PostBack check in the Page_Load event. By adding IsPostBack, this issue will be resolved.

Aspx Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyListViewTest.aspx.cs" Inherits="IgroupUploader.MyListViewTest" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:ListView ID="lvFile" runat="server" OnItemCommand="lvFile_ItemCommand" GroupItemCount="2" GroupPlaceholderID="groupPlaceholder">
        <LayoutTemplate>
        <table>
            <tr>
                <td runat="server" id="groupPlaceholder"></td>
            </tr>
          </table>
        </div>
        </LayoutTemplate>

        <GroupTemplate>
            <tr>
            <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
            </tr>
        </GroupTemplate>
        <GroupSeparatorTemplate>
           <tr><td style="height:23px;"></td></tr>
        </GroupSeparatorTemplate>
        <ItemTemplate>
            <td>
                <asp:LinkButton ID="LinkButton1" CommandName="Delete" runat="server" Text='<%#Eval("OriginalFileName")  %>' >LinkButton</asp:LinkButton>
              </td> 
        </ItemTemplate>
    </asp:ListView>
    </div>
    </form>
</body>
</html>

Code Behind:

 protected void Page_Load(object sender, EventArgs e)
        {
                    GetFileList();

        }

 public void GetFileList()
        {
            DataTable dtFile = new DataTable();
            DataAccessLayer ObjData = new DataAccessLayer();

            //Get all the files uploaded by the logged in user.
            dtFile = ObjData.GetAllFiles(UserHashCode, this.IsAdmin);
            //Bind it to the listview.
            lvFile.DataSource = dtFile;
            lvFile.DataBind();
        }

        protected void lvFile_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Delete"))
            {
                
            }
            
        }

Every thing is fine in the front end. We have to add not IsPostBack in the page load:

Working Code

 protected void Page_Load(object sender, EventArgs e)
        {
                     if (!IsPostBack)
            {
                
                    GetFileList();

            }

        }

 public void GetFileList()
        {
            DataTable dtFile = new DataTable();
            DataAccessLayer ObjData = new DataAccessLayer();

            //Get all the files uploaded by the logged in user.
            dtFile = ObjData.GetAllFiles(UserHashCode, this.IsAdmin);
            //Bind it to the listview.
            lvFile.DataSource = dtFile;
            lvFile.DataBind();
        }

        protected void lvFile_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Delete"))
            {
                
            }
            
        }

Convert Date to string

string date = DateTime.Today.Date.ToString("dd/MM/yyyy"); //Result "27/08/2012"
string date = DateTime.Today.Date.ToString("dd_MM_yyyy"); //Result "27_08_2012"
string date =DateTime.Today.Date.ToString("MMMM"); //Result "August"
string date =DateTime.Today.Date.ToString("MMM"); //Result "Aug"

Query String Set and Get

Send Query String:
Response.Redirect("queryto.aspx?id=4");

Get Query String:
It is better to check for null before using the queystring.
if (string.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
string queryString = Request.QueryString["id"];
}

Data Table to excel c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Reflection;

namespace CallCodeBehindMethodFromJavascript
{
public class Student
{
public string Name { get; set; }
public int StudentId { get; set; }
public int Age { get; set; }
}
public class ListtoDataTableConverter
{
public DataTable ToDataTable(List items)
{
DataTable dataTable = new DataTable(typeof(T).Name);
//Get all the properties
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
{
//Setting column names as Property names
dataTable.Columns.Add(prop.Name);
}

foreach (T item in items)
{
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
{
//inserting property values to datatable rows
values[i] = Props[i].GetValue(item, null);
}

dataTable.Rows.Add(values);

}
//put a breakpoint here and check datatable
return dataTable;

}
}

public partial class Import : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}

protected void btnGetXls_Click(object sender, EventArgs e)
{

List Students = new List(){
new Student() { Name = "Jack", Age = 15, StudentId = 100 },
new Student() { Name = "Smith", Age = 15, StudentId = 101 },
new Student() { Name = "Smit", Age = 15, StudentId = 102 }
};

ListtoDataTableConverter converter = new ListtoDataTableConverter();
DataTable dt = new DataTable();
dt = converter.ToDataTable(Students);
DataTableToExcel(dt);

}

Delete duplicate record from Table SQL

Create Table :

CREATE Table [Order]
(
     ID INT Primary key NOT NULL IDENTITY(1,1),
     NAME NVARCHAR(MAX),
     Quantity INT,
      Price INT
)

Insert duplicate record into the table:

INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘SIBASIS’,1,10)

INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘SIBASIS’,1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘SIBASIS’,1,2)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘SIBASIS’,1,3)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘SIBASIS’,1,11)
 
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Manua’,1,10)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Manua’,1,10)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Manua’,1,10)
 
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Kalia’,1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Kalia’,1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Tiki’,1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES(‘Tiki’,1,1)

Delete Duplicate record:

DELETE FROM [Order] WHERE ID NOT IN (SELECT MAX(ID) FROM [Order] GROUP BY NAME)