Fading image using jquery FadeTo

xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title></title>
 <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
 <script>
 window.setInterval("Method()", 1000);
 Method = function () {
 var ff = parseFloat($("img").css("opacity")).toFixed(1);
 // alert(ff);
 if (ff == 0.6)
 $("img").fadeTo("slow", 1);
 else
 $("img").fadeTo("slow", 0.6);
 };
 </script>
</head>
<body>
<img src="Images/Bald.jpg" width=400 border="0" />
</body>
</html>

Populate Select from ajax with jquery

xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title></title>
 <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
 <script>
 $(document).ready(function () {

$.ajax({ url: "Fetchdata.ashx",
 type: "GET",
 dataType : 'json',
 success: function (msg) {

 $("#ddlcity").get(0).options.length = 0;
 $("#ddlcity").get(0).options[0] = new Option("Select City", "-1");

$.each(msg, function (k, v) {
 //alert(v);
 $("#ddlcity").get(0).options[$("#ddlcity").get(0).options.length] = new Option(v.Name, v.ID);
 });
 },
 error: function (msg) { alert("Error !!!!"); }
 });
 });
 </script>

</head>
<body>
<select id="ddlcity"></select>
</body>
</html>


<%@ WebHandler Language="C#" Class="Fetchdata" %>

using System;
using System.Web;
using System.Collections.Generic;
public class Fetchdata : IHttpHandler {

 public void ProcessRequest (HttpContext context) {
 context.Response.ContentType = "text/plain";
 List Objcity = GetList();
 System.Web.Script.Serialization.JavaScriptSerializer objJs = new System.Web.Script.Serialization.JavaScriptSerializer();
 context.Response.Write( objJs.Serialize(Objcity));
 }

 public bool IsReusable {
 get {
 return false;
 }
 }
 public List GetList()
 {
 List<Citydata> item = new List<Citydata>();
 item.Add(new Citydata() { Name = "Delhi", Id = "1" });
 item.Add(new Citydata() { Name = "Mumbai", Id = "2" });
 item.Add(new Citydata() { Name = "Kolcatta", Id = "3" });
 item.Add(new Citydata() { Name = "Chennai", Id = "4" });
 item.Add(new Citydata() { Name = "Banglore", Id = "5" });
 item.Add(new Citydata() { Name = "Agra", Id = "6" });
 return item;
 }
}

public class Citydata
{
 string _Name = string.Empty;

public string Name
 {
 get { return _Name; }
 set { _Name = value; }
 }
 string _Id = string.Empty;

public string Id
 {
 get { return _Id; }
 set { _Id = value; }
 }

}

server side validation using regular expression and extension method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DAL
{
	public static class Extention
	{
		 const string MatchEmailPattern =
		   @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
	+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
	+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
	+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

		const string NumberPattern=@"^\d$";
		const string AlphbetPattern = @"^[a-zA-Z]*$";
		const string AlphanumricPattern = @"^[a-zA-Z0-9]*$";
		const string AlphNumeric_space = @"[^\w\s]";
		const string AlphaNumeric_spacial = @"^((?:[A-Za-z0-9-'.,@:?!()$#/\\]+|&[^#])*&?)$";
		const string AlphaNumeric_Hyphen = @"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$";
		//Date Constant/////////////////
		const string Dateyyyydddmm_pattern = @"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
		const string Datemmddyyyy_Pattern = @"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$";
		const string Dateddmmyyyy_Pattern = @"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$";
		const string DateddMMMyyyy_Pattern = @"^(0[1-9]|1[012])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[-
/.](19|20)\d\d$";

		const string
Url_Pattern=@"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,|
|>|<|;|\)])";
		public static bool IsEmail(this string value)
		{
			if (value != null)
                return System.Text.RegularExpressions.Regex.IsMatch(value, MatchEmailPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
			   return false;
		}
		public static bool IsNumber(this string value)
		{
			if (value != string.Empty)
                return System.Text.RegularExpressions.Regex.IsMatch(value, NumberPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;

		}
		public static bool IsAlphabet(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, AlphbetPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsAlphaNumeric(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, AlphanumricPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsAlphaNumeric_Space(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, AlphNumeric_space,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsAlphaNumeric_Spacial(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumeric_spacial,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsAlphaNumeric_Hyphen(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumeric_Hyphen,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsDateyyyydddmm(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, Dateyyyydddmm_pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}

		public static bool IsDatemmddyyyy(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, Datemmddyyyy_Pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsDateddmmyyyy(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, Dateddmmyyyy_Pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsDateddMMMyyyy(this string value)
		{
			if (!string.IsNullOrEmpty(value))
				return System.Text.RegularExpressions.Regex.IsMatch(value,
DateddMMMyyyy_Pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
		public static bool IsUrl_Valid(this string value)
		{
			if (!string.IsNullOrEmpty(value))
                return System.Text.RegularExpressions.Regex.IsMatch(value, Url_Pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			else
				return false;
		}
	}

}

custom paging in datagrid-repeater-gridview

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
    a{padding:5px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataGrid ID="Dgpager" runat="server" BackColor="LightGoldenrodYellow"
            BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
            GridLines="None" Width="447px">
            <AlternatingItemStyle BackColor="PaleGoldenrod" />
            <FooterStyle BackColor="Tan" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
                HorizontalAlign="Center" />
            <SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        </asp:DataGrid>
    <div id="pagination">
<asp:Literal ID="litPaging" runat="server" EnableViewState="true"></asp:Literal>
</div>
    </div>
    </form>
</body>
</html>

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int totalRecords = 234;
        int pageSize = 10;
        int totalPages = totalRecords / pageSize + (totalRecords % pageSize > 0 ? 1 : 0);
        int NoofNumaricLink = 7;
         int currentPage = 1;
          if (Request.QueryString["page"] == null)
            currentPage = 1;
        if (Request.QueryString["page"] != null)
        {
            if (!int.TryParse(Request.QueryString["page"].ToString(), out currentPage))
                currentPage = 1;
            if (currentPage > totalPages)
                currentPage = totalPages;
        }

        List<Customer> customers =(new Customer()).GetCustomerList();

        var ObjCustomerslist = customers.Skip((currentPage - 1)*pageSize).Take(pageSize);
        Dgpager.DataSource = ObjCustomerslist;
        Dgpager.DataBind();
        litPaging.Text = CreatePageLinks(totalRecords, pageSize, totalPages, NoofNumaricLink,currentPage);

    }

    string CreatePageLinks(int totalRecords, int pageSize, int totalPages, int TotalNoLink, int currentPage)
    {
        if (totalRecords <= pageSize)
            return "";
        StringBuilder strPager = new StringBuilder();

        string pageUrl = Context.Request.Url.AbsolutePath;

        if (currentPage > 1)
        {
            strPager.Append(string.Format("<a  href='{1}?page={0}' title='First page'>Fist</a>", 1, pageUrl));
            strPager.Append(string.Format("<a  href='{1}?page={0}' title='Previous page'>Previous</a>", (currentPage - 2) + 1,
pageUrl));
        }
        if(!(currentPage > 1))
        {
            strPager.Append("<a herf='javascript:void(0);' title='First Page'>First</a><a herf='javascript:void(0);' title='Previous
page'>Previous</a>");
        }
        int min, max;
        if (TotalNoLink >= totalPages)
        {
            min = 1;
            max = totalPages;
        }
        else
        {
            if (currentPage - TotalNoLink / 2 > 0)
                max = (currentPage + TotalNoLink / 2 - (TotalNoLink - 1) % 2);
            else
                max = TotalNoLink;
            if (max > totalPages) max = totalPages;
            min = max - TotalNoLink + 1 > 0 ? max - TotalNoLink + 1 : 1;
        }
        for (int n = min; n <= max; n++)
        {
            if (n > totalPages)
                break;
            if (n == currentPage)
                strPager.Append(String.Format(" {0}", n.ToString()));
            else
                strPager.Append(String.Format("<a href='{2}?page={1}' title='{0}'>{0}</a> ", n, (n - 1) + 1,pageUrl));
        }
        if (currentPage < totalPages)
        {
            strPager.Append(String.Format("<a href='{1}?page={0}' title='Next Page'>Next</a> ", currentPage + 1, pageUrl));
            strPager.Append(String.Format("<a href='{1}?page={0}' title='Last Page'>Last</a> ", totalPages, pageUrl));
        }
        if (!(currentPage < totalPages))
        {
            strPager.Append("<a herf='javascript:void(0);' title='Next Page'>Next</a><a herf='javascript:void(0);' title='Last
page'>Last</a>");
        }

        return strPager.ToString();
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Customer
{
    string uid = string.Empty;

    public string Uid
    {
        get { return uid; }
        set { uid = value; }
    }
    string name = string.Empty;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    int age = 0;

    public int Age
    {
        get { return age; }
        set { age = value; }
    }
    public List<Customer> GetCustomerList()
    {
        List<Customer> listitem = new List<Customer>();
        for (int n = 1; n < 245; n++)
        {
            listitem.Add(new Customer() { Uid = n.ToString(), Name = "name" + n.ToString(), Age = n * 10 });
        }
        return listitem;
    }
}

Google like Paging in Asp.net


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!--<span class="hiddenSpellError" pre=""-->DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
    a{padding:5px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="pagination">
<asp:Literal ID="litPaging" runat="server" EnableViewState="true"></asp:Literal>
</div>
    </div>
    </form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int totalRecords = 234;
        int pageSize = 10;
        int totalPages = totalRecords / pageSize + (totalRecords % pageSize > 0 ? 1 : 0);
        int NoofNumaricLink = 7;
        litPaging.Text = CreatePageLinks(totalRecords, pageSize, totalPages, NoofNumaricLink);

    }
    string CreatePageLinks(int totalRecords, int pageSize,int totalPages, int TotalNoLink)
    {
        if (totalRecords <= pageSize)
            return "";
        StringBuilder strPager = new StringBuilder();
        int currentPage = 1;
        string pageUrl = Context.Request.Url.AbsolutePath;
        if (Request.QueryString["page"] == null)
            currentPage = 1;
        if (Request.QueryString["page"] != null)
        {
            if (!int.TryParse(Request.QueryString["page"].ToString(), out currentPage))
                currentPage = 1;
            if (currentPage > totalPages)
                currentPage = totalPages;
        }

        if (currentPage > 1)
            strPager.Append(string.Format("<a title="Previous page" href="{1}?page={0}">Previous</a>", (currentPage - 2) + 1, pageUrl));
        int min, max;
        if (TotalNoLink >= totalPages)
        {
            min = 1;
            max = totalPages;
        }
        else
        {
            if (currentPage - TotalNoLink / 2 > 0)
                max = (currentPage + TotalNoLink / 2 - (TotalNoLink - 1) % 2);
            else
                max = TotalNoLink;
            if (max > totalPages) max = totalPages;
            min = max - TotalNoLink + 1 > 0 ? max - TotalNoLink + 1 : 1;
        }
        for (int n = min; n <= max; n++)
        {
            if (n > totalPages)
                break;
            if (n == currentPage)
                strPager.Append(String.Format(" {0}", n.ToString()));
            else
                strPager.Append(String.Format("<a title="{0}" href="{2}?page={1}">{0}</a> ", n, (n - 1) + 1,pageUrl));
        }
        if (currentPage < totalPages)
            strPager.Append(String.Format("<a title="{0}" href="{1}?page={0}">Next</a> ", currentPage+1,pageUrl));
        return strPager.ToString();
    }
}

Posted in C#, Asp.net. 1 Comment »

load image or captcha image using jquery and asp.net

Demo for show image or catptch image on button click using jquery……..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jquery-1.6.1.min.js" type="text/javascript"></script>
<script language="javascript" >
$(document).ready(function () {
$("#btnload").click(function () {
$.get("data.ashx", function (data) {

$("#imgload").attr("src",data);
});

});
});
</script>
</head>
<body>
<img id="imgload" border="0" src="" /> <br />
<button id="btnload">Load Image</button>
</body>
</html>

<%@ WebHandler Language="C#" %>

using System;
using System.Drawing;
using System.Web;
using System.Drawing.Imaging;
using System.IO;
public class data : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Bitmap bmp = new Bitmap(context.Server.MapPath("download.jpg"));
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
bmp.Save(ms, ImageFormat.Jpeg);
byte[] imageBytes = ms.ToArray();

// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
context.Response.Write("data:image/gif;base64," + base64String);
context.Response.End();
}
}

public bool IsReusable
{
get
{
return false;
}
}


}

Sending Mail using CDOSYS

<%
dim returnCode
SendMail
if returnCode = True then
 'Put your code when mail send successfull	
else	
'Put your code when mail could not send	end if


sub SendMail()
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Send test Mail using CDOSYS"
myMail.From="name@yourdomain.com"
myMail.To="name@yourdomain.com"    'You can also use comma separated Mail
myMail.HTMLBody="<b>Hi</b><br/><p>How r you.</p><p>Test mail sending Program</p>"
myMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
myMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.UpdateOn 
Error Resume Next
myMail.Send
If Err.Number = 0 then
returnCode=True
Else
returnCode=False
End If
set myMail=nothing
end sub
%>

Posted in asp. 1 Comment »

get items data at run time using the ItemDataBound, RowDataBound event

 protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        //For Fill Data in DataTable 
        dt = clsemp.GetData();
       //For DataList
        DataList1.DataSource = dt;
        DataList1.DataBind();
        //for GridView
        GridView1.DataSource = dt;
        GridView1.DataBind();
        //for repeater
        Repeater1.DataSource = dt;
        Repeater1.DataBind();

    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (e.Item.DataItem != null)
            {
                int intEmployeeId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "EmployeeId"));
                string strFName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "FirstName"));
                string strLName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LastName"));

                //work do as per require
            }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.DataItem != null)
            {
                int intEmployeeId = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "EmployeeId"));
                string strFName = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "FirstName"));
                string strLName = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "LastName"));

                //work do as per require
            }
        }
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (e.Item.DataItem != null)
            {
                int intEmployeeId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "EmployeeId"));
                string strFName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "FirstName"));
                string strLName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LastName"));

                //work do as per require
            }
        }

    }

Paging ListView With DataPager

<asp:ListView ID="EmpListView" runat="server">
            <LayoutTemplate>
          
                <tr>
                    <td align="center">Employee Data</td>
                </tr>
                       
            </LayoutTemplate>
                            
            <ItemTemplate>
            
                <tr>
                    <td>
                    <br />
                    Employee Id:&nbsp;<b><%# Eval("employeeId") %>'></b>
                    <br /><br />
                    Employee Name::&nbsp;<b><%# Eval("FirstName") %>'>&nbsp;<%# Eval("LastName") %>'></b>
                    <br />
                    </td>
                </tr>
            
            </ItemTemplate>
                    
        </asp:ListView>
         </table>
        <br />
        <asp:DataPager ID="PagerRow" runat="server" PagedControlID="EmpListView" 
            OnPreRender="EmpList_PreRender">
            <Fields>
                <asp:TemplatePagerField>
                    <PagerTemplate>
                        Page
                        <asp:Label runat="server" ID="lbCurrentPage" 
                          Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
                        of
                        <asp:Label runat="server" ID="lbTotalPages" 
                          Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
                        (Total:
                        <asp:Label runat="server" ID="lbTotalItems" 
                          Text="<%# Container.TotalRowCount%>" />
                        records)
                    <br /><br />                 
                    </PagerTemplate>
                </asp:TemplatePagerField>
                
                
                <asp:NextPreviousPagerField ButtonType ="Button" ShowFirstPageButton="True" ShowPreviousPageButton="True" ShowNextPageButton="True" ShowLastPageButton="True" />
               
                <asp:TemplatePagerField OnPagerCommand="PagerNextPrevious_OnPagerCommand">
                    <PagerTemplate>                                            
                        <br /><br />
                                                
                        <asp:LinkButton ID="lbtnFirst" runat="server" CommandName="First" 
                        Text="First" Visible='<%# Container.StartRowIndex > 0 %>' />

                        <asp:LinkButton ID="lbtnPrevious" runat="server" CommandName="Previous" 
                        Text='<%# (Container.StartRowIndex - Container.PageSize + 1) + " - " + (Container.StartRowIndex) %>'
                        Visible='<%# Container.StartRowIndex > 0 %>' />
                        
                        <asp:Label ID="lbtnCurrent" runat="server"
                        Text='<%# (Container.StartRowIndex + 1) + "-" + (Container.StartRowIndex + Container.PageSize > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize) %>' />
                       
                        <asp:LinkButton ID="lbtnNext" runat="server" CommandName="Next"
                        Text='<%# (Container.StartRowIndex + Container.PageSize + 1) + " - " + (Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize*2) %>' 
                        Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
 
                        <asp:LinkButton ID="lbtnLast" runat="server" CommandName="Last" 
                        Text="Last" Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />                        
                    </PagerTemplate>
                </asp:TemplatePagerField>
                
                <asp:TemplatePagerField OnPagerCommand = "PagerNo_OnPagerCommand">            
                    <PagerTemplate>
                        <br /><br />
                        <asp:TextBox ID="txtPageNo" runat="server" Width="30px" onKeyUp = "value = value.replace(/[^0-9]/g,'')"
                        Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" ></asp:TextBox>
                        <asp:Button ID="btnsubmit" runat="server" Text="Go" />
                    </PagerTemplate>            
                </asp:TemplatePagerField>
            </Fields>
        </asp:DataPager>

private void DataBindList()
    {
         connectionlayer dl = new connectionlayer();
         DataSet emp = new DataSet();
         dl.LoadDataSet(CommandType.Text, "SELECT employeeId,LastName,FirstName FROM Employees", ref emp, "emp");
         EmpListView.DataSource = emp;
         EmpListView.DataBind();
       
    }



    protected void PagerNextPrevious_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
    {
        switch (e.CommandName)
        {
           
            case "First":
                e.NewStartRowIndex = 0;
                e.NewMaximumRows = e.Item.Pager.MaximumRows;
                break;
            case "Previous":
                e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize;
                e.NewMaximumRows = e.Item.Pager.MaximumRows;
                break;
            case "Next":
                int NewIndexNo = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize;
                if (NewIndexNo <= e.TotalRowCount)
                {
                    e.NewStartRowIndex = NewIndexNo;
                    e.NewMaximumRows = e.Item.Pager.MaximumRows;
                }
                break;

            case "Last":
                e.NewStartRowIndex = e.TotalRowCount - e.TotalRowCount % e.Item.Pager.PageSize;
                e.NewMaximumRows = e.Item.Pager.MaximumRows;
                break;
        }
    }

    protected void PagerNo_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
    {
        int NewPageNo = Convert.ToInt32((e.Item.FindControl("txtPageNo") as TextBox).Text);
        int NewIndexNo = e.Item.Pager.PageSize * (NewPageNo - 1);
        if (NewIndexNo <= e.TotalRowCount)
        {
            e.NewStartRowIndex = NewIndexNo;
            e.NewMaximumRows = e.Item.Pager.MaximumRows;
        }
    }
    protected void EmpList_PreRender(object sender, EventArgs e)
    {
        DataBindList();
        PagerRow.PageSize = 5;
    }

add edit and delete xml item using XPath and xmlnode

<asp:GridView ID="GridView1"  runat="server" AutoGenerateColumns=false onrowcommand="GridView1_RowCommand" PageSize=20 AllowPaging=true Width="80%" >
                <Columns>

                <asp:TemplateField HeaderText="Sno.">
                <ItemTemplate>
                <%#Container.DataItemIndex+1 %>
                </ItemTemplate>
                </asp:TemplateField>
                 <asp:TemplateField HeaderText="Project Name">
                <ItemTemplate>
                <%#Eval("ProjectName") %>
                </ItemTemplate>
                </asp:TemplateField>
                 <asp:TemplateField HeaderText="Client Name">
                <ItemTemplate>
               <%#Eval("ClientName") %>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Images">
                <ItemTemplate>
                 <img src="../<%#Eval("ThumbImage") %>" width=100 height=100 border=0 />
                </ItemTemplate>
                </asp:TemplateField>
               <asp:TemplateField HeaderText="Action" >
                <ItemTemplate>
                <asp:LinkButton ID="lnklink" Text="Edit" runat="server" CommandName="Edit" CommandArgument='<%#Eval("ProductId") %>' ></asp:LinkButton>
                <asp:Button ID="Button2" runat="server" Text="Delete" CommandName="Del" CommandArgument='<%#Container.DataItemIndex%>' />

                </ItemTemplate>
                </asp:TemplateField>
                </Columns>
                </asp:GridView>

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

public partial class cpanel_Add_Project : System.Web.UI.Page
{
    string  Id
    {
        get
        {
            if (ViewState["Id"] == null)
                return "";
            else
                return (string)ViewState["Id"];
        }
        set
        {
            ViewState["Id"] = value;
        }
    }
    DataSet Table
    {
        get
        {
            if (ViewState["Table"] == null)
                return new DataSet();
            else
                return (DataSet)ViewState["Table"];
        }
        set
        {
            ViewState["Table"] = value;
        }
    }
    string ThumbImage
    {
        get
        {
            if (ViewState["ThumbImage"] == null)
                return "";
            else
                return (string)ViewState["ThumbImage"];
        }
        set
        {
            ViewState["ThumbImage"] = value;
        }
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
        
     
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            Id = Convert.ToString(Request.QueryString["id"]);
        }
        if (!IsPostBack)
        {
           
                BindData();
            
        }

    }
    class ClsProducts
    {
        string _ProductId = string.Empty;

        public string ProductId
        {
            get { return _ProductId; }
            set { _ProductId = value; }
        }
        string _projectName = string.Empty;

        public string ProjectName
        {
            get { return _projectName; }
            set { _projectName = value; }
        }
        string _clientName = string.Empty;

        public string ClientName
        {
            get { return _clientName; }
            set { _clientName = value; }
        }
        string _thumbImage = string.Empty;

        public string ThumbImage
        {
            get { return _thumbImage; }
            set { _thumbImage = value; }
        }
    }
    private void BindData()
    {
        XmlDocument item = new XmlDocument();

        item.Load(Server.MapPath("~/") + "projects.xml");

        XmlNodeList itemdata = item.SelectNodes("//projects/project");
        if (itemdata != null)
        {
            List<ClsProducts> itemProduct = new List<ClsProducts>();
            for (int n = 0; n < itemdata.Count; n++)
            {
                ClsProducts obj = new ClsProducts();
                obj.ProductId = itemdata.Item(n).ChildNodes.Item(0).InnerText;
                obj.ProjectName = itemdata.Item(n).ChildNodes.Item(1).InnerText;
                obj.ClientName = itemdata.Item(n).ChildNodes.Item(2).InnerText;
                obj.ThumbImage = itemdata.Item(n).ChildNodes.Item(3).InnerText;
                itemProduct.Add(obj);

            }
            GridView1.DataSource = itemProduct;
            GridView1.DataBind();
        }
        if (Id != "")
        {
            XmlNode xlist = item.SelectSingleNode("//projects/project[projectID=" + Id + "]");
            if (xlist != null)
            {
                txtProjectName.Value = xlist.ChildNodes.Item(1).InnerText;
                txtprojectClient.Value = xlist.ChildNodes.Item(2).InnerText;
                ThumbImage = xlist.ChildNodes.Item(3).InnerText;
                Image1.ImageUrl = "../" + ThumbImage;
            }
            else
            {
                Image1.Visible = false;
            }
        }
        else
        {
            Image1.Visible = false;
        }
    }
    protected void btnImage_Click(object sender, ImageClickEventArgs e)
    {
        if (UpThumbImage.HasFile)
        {
            string filename = DateTime.Now.ToString("MMddyyyyHHmmss") + UpThumbImage.FileName;
            string location = Server.MapPath("~/images/thumbnails/") + filename;
            UpThumbImage.PostedFile.SaveAs(location);
            ThumbImage = "images/thumbnails/" + filename;
        }
        else
        {
            if (ThumbImage.Length == 0)
            {
                WebUtility.PageAlert(Page, "Please Upload Images!");
                return;
            }
        }
        XmlDocument item = new XmlDocument();

        item.Load(Server.MapPath("~/") + "projects.xml");
        if (Id!="")
        {
           
            XmlNode xlist = item.SelectSingleNode("//projects/project[projectID=" + Id + "]");
            if (xlist != null)
            {
                xlist.ChildNodes.Item(1).InnerText = txtProjectName.Value;
                xlist.ChildNodes.Item(2).InnerText = txtprojectClient.Value;
                xlist.ChildNodes.Item(3).InnerText = ThumbImage;
                item.Save(Server.MapPath("~/") + "projects.xml");


            }

        }
        else
        {
            XmlNodeList xlist1 = item.SelectNodes("//projects/project");
            string xmlvalue=""
    + "<projectID>" + DateTime.Now.ToString("MMddyyHHmmss")+ "</projectID>" +
    "<projectName>"+txtProjectName.Value+"</projectName>"+
    "<projectClient>"+txtprojectClient.Value+"</projectClient>"+
    "<imagethumb>"+ThumbImage+"</imagethumb>"+
    "";
            XmlNode newnode = item.LastChild.FirstChild.Clone();
             
            newnode.InnerXml = xmlvalue;
            item.LastChild.AppendChild(newnode);
            item.Save(Server.MapPath("~/") + "projects.xml");
        }
        BindData();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            Response.Redirect("Add-Project.aspx?id=" + e.CommandArgument.ToString());
        }
        else if (e.CommandName == "Del")
        {
            XmlDocument item = new XmlDocument();
           int n = Convert.ToInt32(e.CommandArgument.ToString());
            item.Load(Server.MapPath("~/") + "projects.xml");
            XmlNodeList xlist = item.SelectNodes("//projects/project");
            xlist.Item(n).ParentNode.RemoveChild(xlist.Item(n));
            item.Save(Server.MapPath("~/") + "projects.xml");

            WebUtility.PageAlert(Page, "Delete Product successfully", "Add-Project.aspx");
        }
    }
}


<?xml version="1.0" encoding="utf-8"?>
<projects>
  <project>
    <projectID>4</projectID>
    <projectName>project 4</projectName>
    <projectClient>client 4</projectClient>
    <imagethumb>images/thumbnails/4.jpg</imagethumb>
   </project>
  <project>
    <projectID>5</projectID>
    <projectName>project 5</projectName>
    <projectClient>client 5</projectClient>
    <imagethumb>images/thumbnails/5.jpg</imagethumb>
 </project>
  <project>
    <projectID>6</projectID>
    <projectName>project 6</projectName>
    <projectClient>client 6</projectClient>
    <imagethumb>images/thumbnails/6.jpg</imagethumb>
</project>
  <project>
    <projectID>7</projectID>
    <projectName>project 7</projectName>
    <projectClient>client 7</projectClient>
    <imagethumb>images/thumbnails/7.jpg</imagethumb>
 </project>
  <project>
    <projectID>102310214626</projectID>
    <projectName>Rishabh Sharma</projectName>
    <projectClient>Rishabh client</projectClient>
    <imagethumb>images/thumbnails/10232010214626client5.png</imagethumb>
   </project>
</projects>

Follow

Get every new post delivered to your Inbox.