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"))
            {
                
            }
            
        }

What is WCF binding and Different Types of binding available.

What is WCF binding?
The binding in the config file tells you the bellow information
1. Binding element describing the transport protocol
2. Binding element that handles message encoding.

A binding should have one binding element, which should have the above 2 information.

BasicHttpBinding
This binding obeys the WS-I Basic Profile 1.1. This communicates using ASMX based web services.
WSHttpBinding
This binding follows the WS-* specifications. It supports distributed transactions, and secure, reliable sessions. This communicates using both HTTP and HTTPS transport Protocol. Messages are transmitted in the form of XML text or Message Transmission Optimization Mechanism (MTOM).
WSDualHttpBinding
Represents a binding that a WCF service can use to configure and expose endpoints that are able to communicate with ASMX-based Web services and clients and other services that conform to the WS-I Basic Profile 1.1
WSFederationBinding
This binding supports the WS-Federation specification. WS-Federation defines several models for providing federated security, based on the WS-Trust, WS-Security, and WS-Secure Conversation specifications.
NetTcpBinding
The name itself is saying that it uses the TCP protocol for communication. It uses binary encoding wile transfering messages. It offers higher performance than the bindings based on the HTTP protocols but less interoperability. It supports transactions, reliable sessions, and secure communications.
NetPeerTcpBinding
This binding supports peer-to-peer communications between applications using the TCP protocol. This binding supports secure communications and reliable, ordered delivery of messages. Messages are transmitted by using a binary encoding.
NetNamedPipeBinding
This binding is very helpful for processes running on a same computer. It gives high performance by using named pipes. This binding supports secure, reliable sessions and transactions. You cannot use this binding to connect to a service across a network.
NetMsmqBinding
The client and service can communicate using Microsoft Message Queue (MSMQ).Messages are stored in a message queue, so the client and the service do not both have to be running at the same time. This binding supports secure, reliable sessions and transactions. Messages use a binary encoding.
MsmqIntegrationBinding
You can build an WCF application, that sends or receives messages from an MSMQ message queue. It is intended for use with existing applications that use MSMQ message queues.

Handle single quote in Javascript

Download demo project
A better way to handle single Quote in javascript while calling webmethod.
Example
Javascript

 function SaveDetails()
        {
            var name = $("#txtName").val().trim();
            var state = $("#txtState").val().trim();

            //JSON.stringify handle the single quote
            var dataList = JSON.stringify({ Name: name, State: state });

            $.ajax({
                type: "post",
                contentType: "application/json; charset=utf-8",
                url: "login.aspx/SaveDetails",
                data: dataList,
                dataType: "json",
                success: function (data, textStatus) {
                    if (data.d == "true") {
                        alert("success");

                    } else {
                        alert("failed");
                    }
                }
            });
        }

webmethod

 [WebMethod]
        [ScriptMethod]
        public static string SaveDetails(string Name,string State)
        {
            try
            {
                return "true";
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

Reference taken from here

500 Internal Server Error while calling webmethod from javascript

To sole this problem in a better way please refere my new blog Handle single quote in Javascript

Please down load the project
This is the error due to single quote in your input parameter

I am going to explain this issue with an example:
there are two input fields in my page

1. Name
2. State

Case1 :
put any value except single quote in both the fields and submit. it will work fine.

Case2 :
put single quote in name field and in state field put any value. Open firebug console and check
result:500 Internal Server Error

Problem : The single quote is creating problem.

Solution:Replace all the single quote in the value with a &clubs; and in webmethod again  replace all the &clubs; with single quote.

login.aspx:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function SaveDetails()
        {
            var name = $("#txtName").val().trim();
            var state = $("#txtState").val().trim();

            //replacing all the single quotes with &clubs;
            name = name.replace(/'/g, '&clubs;');
            state = state.replace(/'/g, '&clubs;');

            //This is the data i am sending to webmethod
            var dataList = "{ 'Name':'" + name + "','State':'" + state + "'}";

            $.ajax({
                type: "post",
                contentType: "application/json; charset=utf-8",
                url: "login.aspx/SaveDetails",
                data: dataList,
                dataType: "json",
                success: function (data, textStatus) {
                    if (data.d == "true") {
                        alert("success");

                    } else {
                        alert("failed");
                    }
                }
            });
        }
    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 100%;">
            <tr>
                <td><span>Name</span></td>
                <td><input id="txtName" type="text" /></td>
            </tr>
            <tr>
                <td><span>State</span></td>
                <td><input id="txtState" type="text" /></td>
            </tr>
            <tr>
                <td colspan="2"><input id="btnSubmit" type="button" value="Save" onclick="SaveDetails()"/></td>
            </tr>
        </table>

    </div>
    </form>

</body>
</html>

login.aspx.cs

using System;
using System.Web.Script.Services;
using System.Web.Services;

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

        }
        [WebMethod]
        [ScriptMethod]
        public static string SaveDetails(string Name,string State)
        {
            try
            {
                //i am replacing the &clubs; with single quote
                Name = Name.Replace("&clubs;", "'");
                State = State.Replace("&clubs;", "'");

                return "true";
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }
}

To sole this problem in a better way please refere my new blog Handle single quote in Javascript

Row delete + JQGRID

You have to edit in Aspx for the JQgrid defination
Suppose previously you have 4 columns  as following.
colNames: [‘TestimonyID’, ‘Name’, ‘Location’, ‘Approved’]
Now you have to add one new column in defination, now the  colNames will be
colNames: [‘TestimonyID’, ‘Name’, ‘Location’, ‘Approved’,’Delete’]
In colModel you have to add the defination for the Delete column.

<script type="text/javascript">
function deleteClick(Id)
{
       window.location.href = window.location.href + "?deleteid=" + Id;
}

$(function () {
    $("#UsersGrid").jqGrid({
        //Please put your corresponding hanler in place of GrdHandler.ashx
        //I have used handler to fetch data from database.
        url: 'GrdHandler.ashx',
        datatype: 'json',
        height: 250,
        width: 600,
        //Define your columns Here.
        colNames: ['TestimonyID', 'Name', 'Location', 'Approved','Delete'],
        colModel: [
                        { name: 'TestimonyID', index: 'TestimonyID', width: 100, hidden: true, sortable: true, search: true, sorttype: 'integer' },
                        { name: 'Name', index: 'Name', width:200, sortable: true, search: true, sorttype: 'string'},
                        { name: 'Location', index: 'Location', width: 200, sortable: true, search: true, sorttype: 'string' },
                        { name: 'Approved', index: 'Approved', width: 100, sortable: true, search: true, sorttype: 'date' },
                        { name: 'Delete', width: 100, sortable: false, search: false, formatter: function (cellvalue, rowId, rowObject) {
                            var requestName, requestID;
                            if ($.isArray(rowObject)) {
                            //For the first page in grid.
                                // access per array. We are currently in the initial grid filling
                                requestID = rowObject[0];
                            } else {
                                //For the all pages except first page in grid.
                                requestID = rowObject.TestimonyID;
                            }
                            return "<a style="cursor: pointer; text-decoration: underline;" onclick="deleteClick(' + requestID + ')">Delete</a>";
                        }
                        }

                    ],
        rowNum: 10,
        rowList: [10, 20, 30],
        mtype: "GET",
        //This property is very usefull.
        loadonce: true,
        pager: '#UsersGridPager',
        sortname: 'TestimonyID',
        viewrecords: true,
        sortorder: 'asc',
        sortable: true,
        //Change your table name
        caption: 'Testimony Table',
        //Ignore Case while searching
        ignoreCase: true,
        editurl: 'GrdHandler.ashx',
        onPaging: function (b) {
            var nextPg = $(this).getGridParam("page");
            currPg = nextPg;
            return;
        }
    });
    jQuery("#UsersGrid").jqGrid('filterToolbar', { searchOperators: false, searchOnEnter: false, autosearch: true });
});
></script>

In browser the Grid will look like
Delete + Jqgrid
In the code behind get the deleteid from the query string and delete it using your normal code as following

 protected void Page_Load(object sender, EventArgs e)
        {
            int deleteId = 0;

                if (!IsPostBack)
                {
                    //Check the query string deletedId
                    if (int.TryParse(Request.QueryString["deleteid"], out deleteId))
                    {
                        DeleteRecord(deleteId);
                    }
                }

        }
 private void DeleteRecord(int testimonyId)
        {

        }