//
you're reading...
ASP.NET, Database, IT-Center, SQL Server

ASP.NET Datagrid with pagination

Create aspx file and write name with “customer.aspx”

<asp:datagrid id="dgCustomer" runat="server" BackColor="White" Width="100%" AutoGenerateColumns="False"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" GridLines="Vertical" ForeColor="Black"
AllowPaging="True" PageSize="20" PagerStyle-Position="TopAndBottom" PagerStyle-Mode="NumericPages"
CssClass="pager">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="Black"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>

<asp:BoundColumn Visible="False" DataField="CIF"></asp:BoundColumn>

<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<input type="checkbox" id="chkDelCustomer" runat="server" NAME="chkDelCustomer">
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CIF" HeaderText="CIF">
<ItemStyle Width="15%" CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>
<asp:BoundColumn DataField="CUST_NAME" HeaderText="Customer Name">
<ItemStyle CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>
<asp:BoundColumn DataField="NPWP" HeaderText="NPWP">
<ItemStyle CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>

<asp:BoundColumn DataField="BRANCH_NAME" HeaderText="Branch">
<ItemStyle CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>
<asp:BoundColumn DataField="SALES_CODE" HeaderText="Sales Code">
<ItemStyle CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>
<asp:BoundColumn DataField="SALES_NAME" HeaderText="Sales Name">
<ItemStyle CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>
<asp:BoundColumn DataField="BU" HeaderText="BU">
<ItemStyle CssClass="record_item"></ItemStyle>
<HeaderStyle ForeColor="White" />
</asp:BoundColumn>

<asp:HyperLinkColumn Text="Edit" DataNavigateUrlField="CIF" DataNavigateUrlFormatString="javascript:fCusDetail('{0}');">
<ItemStyle HorizontalAlign="Center" Width="5%" CssClass="record_item"></ItemStyle>
</asp:HyperLinkColumn>
<asp:HyperLinkColumn Text="NPWP" DataNavigateUrlField="CIF" DataNavigateUrlFormatString="javascript:fCusDetailNPWP('{0}');">
<ItemStyle HorizontalAlign="Center" Width="5%" CssClass="record_item"></ItemStyle>
</asp:HyperLinkColumn>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
</asp:datagrid>

note datagrid tag AllowPaging=”True” PageSize=”20″ PagerStyle-Position=”TopAndBottom” PagerStyle-Mode=”NumericPages”. If you want change pagination style using that tag and change the value according your taste.
Tag CssClass=”pager” have function to coloring your page number style. Below the css script, you can write that between tag head using <style> tag or include in your css.

/*----------------*/
/*-- datagrid css */
/*----------------*/
.pager a
{
border: 1px solid #EDF5FF;
color: #0067A5;
text-decoration: underline;
padding: 2px 5px;
}
.pager span
{
background-color: #0067A5;
border: 1px solid #DBEAFF;
color: #FFFFFF;
padding: 2px 5px;
}

.pager a:hover
{
color: #1E90FF;
}

/*--------------++--++------*/
/*-- end of datagrid css -- */
/*---------------++--++-----*/

Fill the page_load sub :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      GetDataListOfCustomer()
end sub

Public sub GetDataListOfCustomer()
       Dim sql As String = "select tbl_cust.*, tbl_branch.branch_name  " & _
      "from [tbl_cust] left join tbl_branch on  tbl_cust.sol_id=tbl_branch.sol_id" & _
       " ORDER BY CIF asc"

Dim myObj As New globalFunction
Dim myComm As SqlDataAdapter
myComm = myObj.sqlAdpExec(sql)
Dim ds As New DataSet
myComm.Fill(ds, "dg")
dgCustomer.DataSource = ds.Tables("dg").DefaultView

   Try
          dgCustomer.DataBind()
   Catch ex As Exception
          dgCustomer.CurrentPageIndex = 0
          dgCustomer.DataBind()
   End Try
End Sub

Protected Sub dgCustomer_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgCustomer.PageIndexChanged
    dgCustomer.CurrentPageIndex = e.NewPageIndex
     GetDataListOfCustomer()
End Sub

About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

December 2011
M T W T F S S
« Nov   Jan »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Web Statistic

Blog Stats

  • 149,580 hits
%d bloggers like this: