I use this instead.
It's better than changing the forecolor so we need not keep track of the original forecolor before overwriting it with backcolor.
if (dgSearch.Items.Count == 0)
dgSearch.PagerStyle.Visibl
else
dgSearch.PagerStyle.Visibl
Main Topics
Browse All Topics





by: madhevan_pillaiPosted on 2007-10-29 at 22:49:20ID: 20174989
Hi,
spx.cs" Inherits="Database_DataGri dPaging" %>
l1/DTD/xht ml1-transi tional.dtd ">
999/xhtml" > ch_PageInd exChanged" AllowCustomPaging="True" Width="600px" ="Right" OnItemCreated="dgSearch_It emCreated" >
WebParts; ;
object source, DataGridPageChangedEventAr gs e) ndex = e.NewPageIndex;
nt ==0 ) oreColor =this.dgSearch.PagerStyle. BackColor; t sender, DataGridItemEventArgs e) TableCell) e.Item.Con trols[0]). Attributes .Add("cols pan", "2");
Try this. Run this sample
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataGridPaging.a
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm
<html xmlns="http://www.w3.org/1
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid ID="dgSearch" runat="server" AllowPaging="True"
CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="2" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
OnPageIndexChanged="dgSear
PagerStyle-HorizontalAlign
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditItemStyle BackColor="#2461BF" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" ForeColor="White" HorizontalAlign="Right"
Mode="NumericPages" Position="Top" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#EFF3FB" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
</asp:DataGrid>
</div>
</form>
</body>
</html>
codebehind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
public partial class Database_DataGridPaging : System.Web.UI.Page
{
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
//comment this two line below to check page number
dt.Rows.Add(new Object[] { 1, "aaa" });
dt.Rows.Add(new Object[] { 2, "bbb" });
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindData();
}
}
protected void dgSearch_PageIndexChanged(
{
this.dgSearch.CurrentPageI
BindData();
}
private void BindData()
{
this.dgSearch.DataSource = GetData();
this.dgSearch.DataBind();
if(this.dgSearch.Items.Cou
this.dgSearch.PagerStyle.F
}
protected void dgSearch_ItemCreated(objec
{
if (e.Item.ItemType == ListItemType.Pager)
(( System.Web.UI.WebControls.
}
}