C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Gridview with navigation options like Next,Previous,Last and First


Posted Date: 12 Aug 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: UltimateRenganMember Level: Diamond    
Rating: 1 out of 5Points: 10



Abstract


Here we will discuss about how to bind database values to grid view and how to set next,previous,last and first property for gridview control.
Step 1
Just Drag and drop the Grid view control to page.
Step 2
Click the grid view control then go to the property window(F4).
Step 3
Set Allow paging equal to True(By Default False)
Step 4
Then go to the pager setting
Step 5
Set FirstpageText equal to First
Step 6
Set LastpageText equal to Last
Step 7
Set NextpageText equal to Next
Step 8
Set PreviouspageText equal to Previous
Step 9
Set Mode equal to select NextPreviousFirstLast from dropdownlist
Step 10
Position equal to Bottom
Step 11
Page Size equal to 10(By Default 10)

Take the below example:-



Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Dim ds As New DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Gridbind()
End If
End Sub
Sub Gridbind()

'bind the database values to Gridveiw using dataset control

Dim con As SqlClient.SqlConnection
Dim da As SqlDataAdapter
Dim str As String
str = "USER=userid;PASSWORD=password;SERVER=servername;DATABASE=databasename"
con = New SqlConnection(str)
da = New SqlDataAdapter("select Field1,Field2 from Tablename", con)
da.Fill(ds, "Employee")
GridView1.DataSource = ds
GridView1.DataBind()
con.Close()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
Gridbind()
End Sub
End Class



< %@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

< !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>Untitled Page</title>

< /head>
< body>
< form id="form1" runat="server">
< div>
< asp:GridView ID="GridView1" runat="server" AllowPaging="True">
< PagerSettings FirstPageText="First" LastPageText="Last"
Mode="NextPreviousFirstLast" NextPageText="Next" PreviousPageText="Previous" />
< /asp:GridView>
< /div>
< /form>
< /body>
< /html>




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Previous  .  Navigation in Gridview  .  Last and First  .  Gridview with Next  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Alert Message through code behind
Previous Resource: Binding datalist with next 14 days and checkbox
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use