aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Wednesday, November 24, 2010 Total Views:  

 

GridView is one of most widely used control and we can do lots of things with this control. In ASP.Net 2.0, DataGrid is replaced by GridView control while DataGrid control is still supported. There are large numbers of tasks that can be done through GridView control.

Here’s is the solution.


     <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="false"
               PageSize="5" OnPageIndexChanging="GridView1_PageIndexChanging">
               <Columns>
                   <asp:TemplateField>
                       <HeaderTemplate>
                           Sr.#
                       </HeaderTemplate>
                       <ItemTemplate>
                           <%# Container.DataItemIndex + 1 %>
                       </ItemTemplate>
                   </asp:TemplateField>
                   <asp:BoundField DataField="FullName" HeaderText="Full Name" />
                   <asp:BoundField DataField="Age" HeaderText="Age" />
               </Columns>
       </asp:GridView>

 

Code Behind

   protected void Page_Load(object sender, EventArgs e)
   {
       GridView1.DataSource = fetchAllEmployee().ToList<Employee>();
       GridView1.DataBind();

   }
   protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       GridView1.PageIndex = e.NewPageIndex;
       GridView1.DataBind();
   }
   public List<Employee> fetchAllEmployee()
   {
       return new List<Employee>()
       {
           new Employee{ Fullname="Aamir Hasan",age=26},
           new Employee{ Fullname="Awais Ahmed",age=18},
           new Employee{ Fullname="Mahwish khan",age=24},
           new Employee{ Fullname="Gill",age=55},
           new Employee{ Fullname="Saba khan",age=19},
           new Employee{ Fullname="adnan",age=26},
           new Employee{ Fullname="fasial hameed",age=20},
           new Employee{ Fullname="Aamir Hasan",age=16},
           new Employee{ Fullname="John",age=45},
           new Employee{ Fullname="Suprotim Agarwal ",age=34},
           new Employee{ Fullname="sana",age=24}
       };
   }

   public class Employee
   {
       public String Fullname { get; set; }
       public int age { get; set; }
   }

 

VB.NET

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
       GridView1.DataSource = fetchAllEmployee()
       GridView1.DataBind()
   End Sub
   Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
       GridView1.PageIndex = e.NewPageIndex
       GridView1.DataBind()
   End Sub
   Public Function fetchAllEmployee() As List(Of Employee)
       Dim emps As New List(Of Employee)()
       emps.Add(New Employee() With { _
        .Fullname = "Aamir Hasan", _
        .age = 26 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "Awais Ahmed", _
        .age = 18 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "Mahwish khan", _
        .age = 24 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "Gill", _
        .age = 55 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "Saba khan", _
        .age = 19 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "adnan", _
        .age = 26 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "fasial hameed", _
        .age = 20 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "Aamir Hasan", _
        .age = 16 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "John", _
        .age = 45 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "Suprotim Agarwal ", _
        .age = 34 _
       })
       emps.Add(New Employee() With { _
        .Fullname = "sana", _
        .age = 24 _
       })

       Return emps
   End Function

   Public Class Employee
       Public Property Fullname() As [String]
           Get
               Return m_Fullname
           End Get
           Set(ByVal value As [String])
               m_Fullname = Value
           End Set
       End Property
       Private m_Fullname As [String]
       Public Property age() As Integer
           Get
               Return m_age
           End Get
           Set(ByVal value As Integer)
               m_age = Value
           End Set
       End Property
       Private m_age As Integer
   End Class

Note:Following error message shown to you when you set AllowPaging="True" in gridview control.“The GridView fired event PageIndexChanging which wasn’t handled error message.”,you all need to add event handler  GridView1_PageIndexChanging  of gridview control which is already added in above code.


Output

Download

Row number in gridview.zip (2.54 kb)

See live demo


Protected by Copyscape Online Plagiarism Tool

Comments (19) -

quantum hall effect
quantum hall effect United States
11/25/2010 12:27:35 PM #

You made fantastic nice points here. I performed a search on quantum hall effect the issue and discovered almost all peoples will agree with  your blog.

gul
gul United States
11/28/2010 8:49:48 PM #

thanks, it is working in IE9.

wedge heels shoes
wedge heels shoes United States
11/29/2010 2:58:51 PM #

Cool, there is actually some good points on here some of my readers will maybe find this

relevant, will send a link, many thanks.

Sobia
Sobia Canada
12/3/2010 5:16:52 AM #

Excellent work,

laser marking machine
laser marking machine People's Republic of China
12/20/2010 6:53:21 PM #

Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.

Sofya Skya
Sofya Skya United States
12/24/2010 6:58:21 AM #

Name of the young but very talented actress and dancer Sophia Arzhakovskoy in recent years has been on the pages of newspapers and TV screens.

dye sub ink
dye sub ink People's Republic of China
12/28/2010 6:14:56 PM #

I am visiting this site first time & it has awesome information. I have come to know a lot of information after visiting this site. Keep this sort of posting in future as well.

Софья
Софья United States
12/30/2010 8:51:10 PM #

Благотворительная деательность Софьи Аржаковской.

Dubai property for sale
Dubai property for sale United States
1/1/2011 9:50:33 PM #

Valuable information! Looking forward to seeing your notes posted.

employment software
employment software United States
1/5/2011 1:10:25 AM #

Great. ..you have beautifully presented your thoughts in this blog post.

Apartment in Dubai
Apartment in Dubai U.A.E.
1/31/2011 1:01:50 AM #

Merging all the great knowledge in one book is simply an awesome idea. I like the way to think.

apartments for sale Dubai
apartments for sale Dubai United States
5/18/2011 9:03:44 PM #

Wow, what a great site you have there. It's always good to see a site like this.

t-shirt druck
t-shirt druck United States
5/18/2011 9:06:05 PM #

Nice post here. It does make senses, appreciate for sharing!!!

Dubai villas
Dubai villas U.A.E.
6/18/2011 9:52:24 PM #

I can see that you are an expert at your field! Thanks for all your help and wishing you all the success in your business.

Hosting company India
Hosting company India United States
11/5/2011 1:24:01 AM #

Wonderful post - I was looking for a similar article. Thanks for sharing this article to your reader. You give very nice information about this article

iit preparation
iit preparation United States
11/5/2011 1:58:09 AM #

I enjoy you because of Thank you for all of the every one of your effort hard work on this site.

sta je www
sta je www Serbia
2/18/2012 1:39:13 AM #

A best source for information, no cost, unlimited support for pupils and studens, no need for books and television.

sta je www
sta je www Serbia
2/18/2012 1:39:32 AM #

I use this site all the time, much like many other internet users, I suppose. It's a fantastic source of information. http://saznaj.in/

feel
feel People's Republic of China
5/2/2012 11:40:03 PM #


Cheap NFL,NBA,MLB,NHL [url=http://www.annajerseys.com/]China Jerseys[/url],[url=http://www.annajerseys.com/]China Jerseys Paypal[/url] For Sale online.[url=www.annajerseys.com/...ke-nfl-jerseys-c-1_478.html]2012 Nike NFL Jerseys[/url],All Our Jerseys Are Sewn On and Directly From [url=www.annajerseys.com/...d-patriots-c-1_478_498.html]Nike New England Patriots Jerseys[/url] Factory2012 [url=www.annajerseys.com/.../...fl-jerseys-c-1_478.html]Nike NFL Jerseys China[/url] Wholesale,Wholesale [url=www.annajerseys.com/...falo-bills-c-1_478_482.html]Nike Buffalo Bills Jerseys[/url] From,The high quality Nike NFL Jerseys are  [url=www.annajerseys.com/...oston-bruins-c-124_133.html]Boston Bruins Jerseys[/url] great gifts [url=www.annajerseys.com/...o-blackhawks-c-124_137.html]Chicago Blackhawks Jerseys China[/url] for Arizona Cardinals  [url=www.annajerseys.com/...e-seahawks-c-1_478_507.html]Nike Seattle Seahawks Jerseys[/url].Welcome to our [url=http://www.annajerseys.com/]http://www.annajerseys.com/[/url] to pick [url=www.annajerseys.com/...hia-eagles-c-1_478_503.html]Nike Philadelphia Eagles Jerseys[/url] the hotest [url=www.annajerseys.com/.../...fl-jerseys-c-1_478.html]2012 New NFL Jerseys[/url].
[/pre]

  Best Converse Online Store From UK,Sale 2011 Newest [url=www.sale-converse.com/...rse-flag-shoes-c-130.html]Converse Flag Shoes[/url],Black Converse,[url=www.sale-converse.com/...ewest-converse-c-135.html]Converse 2012[/url],[url=http://www.sale-converse.com/]Cheap Converse[/url] Navy Converse And So on [url=www.sale-converse.com/...-hitop-uk-flag-p-899.html]Converse 2011 All Star Shoes Hi-top UK Flag[/url],[url=http://www.sale-converse.com/]Converse UK[/url],[url=www.sale-converse.com/...rica-flag-red-p-1037.html]Converse 2011 All Star Shoes Hi-top America Flag Red[/url]Free Shipping
[/pre]

We are professional jerseys manufacturer from china,wholesal sports [url=http://www.anna-jersey.com/nfl-jerseys-c-773.html]NFL jerseys China[/url],[url=http://www.anna-jersey.com/nhl-jerseys-c-882.html]NHL Jerseys China[/url],[url=http://www.anna-jersey.com/nba-jerseys-c-821.html]NBA Jerseys China[/url],[url=http://www.anna-jersey.com/mlb-jerseys-c-694.html]MLB Jerseys China[/url],[url=http://www.anna-jersey.com/]China Jerseys[/url],  [url=www.anna-jersey.com/...nike-nfl-jerseys-c-943.html]2012 Nike NFL Jerseys[/url],[url=www.anna-jersey.com/...chicago-cubs-c-694_702.html]Chicago Cubs Jerseys China[/url], Free Shipping
[/pre]
[pre]
,[url=http://www.china4jersey.com/nhl-jerseys-c-512.html]NHL Jerseys China[/url] Paypal,[url=http://www.china4jersey.com/]China Jerseys Paypal[/url] factory,Sewn On Jerseys,Accept Paypal,Free Shipping,[url=www.china4jersey.com/nike-nfl-2012-c-638.html]Nike NFL Jerseys Paypal[/url]   ,Nike Jerseys,[url=www.china4jersey.com/nike-nfl-2012-c-638.html]NFL Jerseys 2012[/url],[url=www.china4jersey.com/nike-nfl-2012-c-638.html]Nike Jerseys China[/url],[url=www.china4jersey.com/nike-nfl-2012-c-638.html]Wholesale Nike Jerseys China[/url][url=http://www.nikenflchina.com/]Nike NFL Jerseys[/url],[url=http://www.nikenflchina.com/]New NFL Jerseys 2012[/url],[url=http://www.nikenflchina.com/]Nike NFL Jerseys China[/url],[url=www.nikenflchina.com/...nike-nfl-jerseys-c-73.html]2012 Nike NFL Jerseys[/url],[url=www.china4jersey.com/...ton-red-sox-c-398_401.html]Boston Red Sox[/url]Professional Online Wholesale Shop From China,We are Chinese Jerseys Manufactruer,Wholesale All Team Of Nike NFL Jerseys,2012 New NFL Jeresys,NFL Jerseys China,Nike Jerseys China,New NFL Jerseys,All Jerseys are embroidered on,Free Shipping To World Wide
[/pre]

Professional Converse Online Store From UK,[url=http://www.converse2you.com/]Converse UK[/url] Shop,Sale 2012 Newest Converse All Stars,Converse Flag Shoes,[url=http://www.converse2you.com/]Cheap Converse[/url],[url=http://www.converse2you.com/]Converse Sale[/url],[url=www.converse2you.com/index.php]Converse Flag Shoes[/url] ,[url=www.converse2you.com/index.php]New Converse 2012[/url] Free Shipping To World Wide.
[/pre]

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5