or
<
style type="text/css">
/* Set the desired properties to the custom buttons */
a.adminLoginStyleClass.rtbWrap .rtbText
{
font-size: 12px;
background: url('./images/administration.png') no-repeat left center;
}
a.logoffStyleClass.rtbWrap .rtbText
{
font-size: 12px;
background: url('./images/logoff.png') no-repeat left center;
}
</
style>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
GridLines
=
"None"
AllowPaging
=
"True"
AllowFilteringByColumn
=
"true"
AllowSorting
=
"True"
AutoGenerateColumns
=
"false"
PageSize
=
"50"
Height
=
"410px"
Skin
=
"Hay"
>
<
MasterTableView
DataKeyNames
=
"customerId"
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Edit"
HeaderText="<span
style
=
'visibility: hidden;'
>a</
span
>" SortExpression="Edit"
UniqueName="Edit" HeaderStyle-Width="40px" AllowFiltering="false" AllowSorting="false">
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"name"
HeaderText
=
"Name"
SortExpression
=
"name"
UniqueName
=
"name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"address"
HeaderText
=
"Address"
SortExpression
=
"address"
UniqueName
=
"address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"city"
HeaderText
=
"City"
SortExpression
=
"city"
UniqueName
=
"city"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"state"
HeaderText
=
"State"
SortExpression
=
"state"
UniqueName
=
"state"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"zip"
HeaderText
=
"Zip"
SortExpression
=
"zip"
UniqueName
=
"zip"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"phone"
HeaderText
=
"Phone"
SortExpression
=
"phone"
UniqueName
=
"phone"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"fax"
HeaderText
=
"Fax"
SortExpression
=
"fax"
UniqueName
=
"fax"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"email"
HeaderText
=
"Email"
SortExpression
=
"email"
UniqueName
=
"email"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"additional"
HeaderText
=
"Additional Info"
SortExpression
=
"additional"
UniqueName
=
"additional"
ItemStyle-Width
=
"200"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
HeaderStyle
Width
=
"120px"
/>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
SaveScrollPosition
=
"True"
>
</
Scrolling
>
</
ClientSettings
>
</
telerik:RadGrid
>
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
If
Not
(Page.IsPostBack)
Then
RadGrid1.DataSource = myFunctions.customerListTable()
RadGrid1.DataBind()
End
If
End
Sub
Protected
Sub
RadGrid1_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
RadGrid1.NeedDataSource
RadGrid1.DataSource = myFunctions.customerListTable()
End
Sub
'this function creates a data table for the customer list
Public
Shared
Function
customerListTable()
Dim
sql =
"SELECT customerId, name, address, city, state, zip, phone, email, fax, additional FROM Customers"
& _
" WHERE deleted = 'false' ORDER BY name"
Dim
conn
As
String
= System.Configuration.ConfigurationManager.ConnectionStrings(
"connection"
).ToString
Using myConn
As
New
SqlConnection(conn)
'create the table
Dim
myTable
As
New
DataTable
myTable.Columns.Add(
"customerId"
)
myTable.Columns.Add(
"edit"
)
myTable.Columns.Add(
"name"
)
myTable.Columns.Add(
"address"
)
myTable.Columns.Add(
"city"
)
myTable.Columns.Add(
"state"
)
myTable.Columns.Add(
"zip"
)
myTable.Columns.Add(
"phone"
)
myTable.Columns.Add(
"email"
)
myTable.Columns.Add(
"fax"
)
myTable.Columns.Add(
"additional"
)
myConn.Open()
Dim
cmd
As
New
SqlCommand(sql, myConn)
Dim
reader = cmd.ExecuteReader
While
reader.Read()
myTable.Rows.Add(reader(
"customerId"
),
"<a href="
"../Customers/EditCustomer.aspx?id"
& reader(
"customerId"
) &
""
">Edit</a>"
, _
reader(
"name"
), reader(
"address"
), reader(
"city"
), reader(
"state"
), reader(
"zip"
), _
reader(
"phone"
), reader(
"email"
), reader(
"fax"
), reader(
"additional"
))
End
While
'while reader.read
myConn.Close()
Return
myTable
End
Using
'using myConn
End
Function
'customerListTable
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPlaceholder.master" AutoEventWireup="true" CodeFile="AccountsTest.aspx.cs" Inherits="Accounts_AccountsTest" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
Runat
=
"Server"
>
<!-- custom head section -->
<
style
type
=
"text/css"
>
.GridPager_Default INPUT
{
border: 1px solid gray;
height: 14px;
font-size: 11px;
}
.CustomPagerHolder
{
float:left;
}
.NumericPagerHolder
{
float:right;
}
</
style
>
<!-- end of custom head section -->
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
/>
<!-- content start -->
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"DropDownList1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
OnPreRender
=
"RadGrid1_PreRender"
ShowStatusBar
=
"true"
runat
=
"server"
AutoGenerateColumns
=
"False"
PageSize
=
"10"
AllowSorting
=
"True"
AllowMultiRowSelection
=
"False"
AllowPaging
=
"True"
GridLines
=
"None"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnItemCreated
=
"RadGrid1_ItemCreated"
>
<
MasterTableView
DataKeyNames
=
"Account_ID"
AllowMultiColumnSorting
=
"True"
DataMember
=
"Accounts"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"Account_ID"
Width
=
"100%"
DataMember
=
"Detail"
runat
=
"server"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"Account_ID"
MasterKeyField
=
"Account_ID"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"Legal_Name"
HeaderText
=
"Legal Name"
HeaderButtonType
=
"TextButton"
DataField
=
"Legal_Name"
UniqueName
=
"LegalName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Current_Effective_Date"
HeaderText
=
"Current Effective Date"
HeaderButtonType
=
"TextButton"
DataField
=
"Current_Effective_Date"
UniqueName
=
"CurrentEffectiveDate"
DataFormatString
=
"{0:D}"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"Account_ID"
HeaderText
=
"AccountID"
HeaderButtonType
=
"TextButton"
DataField
=
"Account_ID"
UniqueName
=
"AccountID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Account_Name"
HeaderText
=
"Account Name"
HeaderButtonType
=
"TextButton"
DataField
=
"Account_Name"
UniqueName
=
"AccountName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
PagerStyle
Mode
=
"NumericPages"
PageButtonCount
=
"5"
AlwaysVisible
=
"true"
></
PagerStyle
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
asp:Content
>
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HealthConnect.DAL;
using Telerik.Web.UI;
public partial class Accounts_AccountsTest : HealthConnect.Web.AMS.AMSPage
{
private DataSet getData()
{
{snip query setup}
DataSet dataSet = db.ExecuteDataSet(dbCommand);
dataSet.Tables[0].TableName = "Accounts";
dataSet.Tables[1].TableName = "Paging";
dataSet.Tables[2].TableName = "Detail";
DataColumn[] quotedGridParentColumns = {
dataSet.Tables["Accounts"].Columns["Account_ID"] };
DataColumn[] planChildColumns = {
dataSet.Tables["Detail"].Columns["Account_ID"] };
DataRelation dr = new DataRelation("pkPlanDetail",
quotedGridParentColumns, planChildColumns, false);
dataSet.Relations.Add(dr);
return dataSet;
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataSet dataSet = getData();
RadGrid1.DataSource = dataSet;
ViewState["PagingInfo"] = dataSet.Tables[1];
ViewState["CurrentPage"] = RadGrid1.CurrentPageIndex;
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridPagerItem)
{
//
// If this is uncommented detail doesn't work, if this is commented detail works.
//
//GridPagerItem item = (GridPagerItem)e.Item;
//Control numericPager = item.GetNumericPager();
//item.PagerContentCell.Controls.Clear();
//Panel myPagerPanel = new Panel();
//myPagerPanel.CssClass = "CustomPagerHolder";
//myPagerPanel.Controls.Add(new MyPager(e.Item.OwnerTableView.PagingManager, e.Item.OwnerTableView, (DataTable)ViewState["PagingInfo"], (int)ViewState["CurrentPage"]));
//item.PagerContentCell.Controls.Add(myPagerPanel);
}
}
private class MyPager : Control
{
private GridPagingManager paging;
private GridTableView tableView;
private DataTable dataTable;
private int currentPage = 0;
DropDownList dropDownList;
public MyPager(GridPagingManager paging, GridTableView tableView, DataTable dataTable, int currentPage)
{
this.paging = paging;
this.tableView = tableView;
this.dataTable = dataTable;
this.currentPage = currentPage;
this.EnsureChildControls();
}
protected override void CreateChildControls()
{
this.Controls.Add(new LiteralControl("Page: "));
dropDownList = new DropDownList();
dropDownList.ID = "DropDownList1";
dropDownList.DataTextField = "Text";
dropDownList.DataValueField = "Value";
dropDownList.SelectedIndexChanged += new EventHandler(this.SelectedIndexChanged);
dropDownList.AutoPostBack = true;
this.Controls.Add(dropDownList);
}
protected override void OnPreRender(EventArgs e)
{
dropDownList.DataSource = this.dataTable;
dropDownList.DataBind();
// This doesn't work, CurrentPageIndex is always 0
//dropDownList.SelectedIndex = this.paging.CurrentPageIndex;
dropDownList.SelectedIndex = currentPage;
base.OnPreRender(e);
}
private void SelectedIndexChanged(object sender, EventArgs e)
{
this.tableView.CurrentPageIndex = dropDownList.SelectedIndex;
this.tableView.Rebind();
}
}
}