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>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|