http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=B12283DE-DB20-4322-ACCC-12724442808A
解决方案 »
- 无法加载 DLL“oramts.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)
- 求substring用法
- 怎么去掉读出的nbsp符号
- 运行出现的奇怪的问题
- 问:DataGrid.Columns.Count 的值 问题!
- HttpRequest中不包含对UserHostName的定义吗?
- .NET我的VS上怎么没有Response.Headers属性如何解决
- 为什么gridview就不能格式化呢?急
- 如何实现这样的功能
- 请教高手:如何做一个分帧显示的页面?(vb.net)在线等待,马上给分。
- 如果得到DataGrid控件中HyperLink的URL
- 请高手近来帮偶解决这个小问题!感激不尽!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" runat="server">
<asp:datagrid id="MyDataGrid" runat="server" AlternatingItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellSpacing="0"
CellPadding="3" GridLines="Both" BorderWidth="1" BorderColor="black"
OnPageIndexChanged="MyDataGrid_Page" PagerStyle-HorizontalAlign="Right"
PagerStyle-Mode="NumericPages" PageSize="5" AllowPaging="True">
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<PagerStyle HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
<p style="font-size:9pt">
<asp:label id="lblPageCount" runat="server"></asp:label>
<asp:label id="lblCurrentIndex" runat="server"></asp:label>
<asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server"
Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="0">
</asp:linkbutton>
<asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server"
Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="prev">
</asp:linkbutton>
<asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server"
Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="next">
</asp:linkbutton>
<asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server"
Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="last">
</asp:linkbutton>
</p>
</form>
</body>
</HTML>
{
namespace WebControl
{ using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; public delegate void BindDataDelegate();
public abstract class dgNavigation : System.Web.UI.UserControl
{ public BindDataDelegate BindData1; private DataGrid _dg;//目标Grid
private bool _autohidden = true;//自动隐藏
private int _pagesize = 10;//缺省分页数
protected System.Web.UI.WebControls.Label LabelMsg;
protected System.Web.UI.WebControls.Button btnNavLast;
protected System.Web.UI.WebControls.Button btnNavNext;
protected System.Web.UI.WebControls.Button btnNavPrevious;
protected System.Web.UI.WebControls.Button btnNavFirst;
protected System.Web.UI.WebControls.TextBox tbPage;
protected System.Web.UI.WebControls.Button btnNavGo;
protected System.Web.UI.WebControls.Label LabelMsg2;
protected System.Web.UI.WebControls.Panel divPanel;//每页显示行数
private int _itemcount = 0;//数据总数
private int _dispStyle = 1;//显示风格 public DataGrid Target
{
get { return _dg; }
set { _dg = value;}
} public bool AutoHidden
{
get { return _autohidden; }
set { _autohidden = value;}
} public int PageSize
{
get { return _pagesize; }
set { _pagesize = value;}
} public int ItemCount
{
get { return _itemcount; }
set { _itemcount = value;}
} private void Page_Load(object sender, System.EventArgs e)
{ } /// <summary>
/// 设置导航对象的目标DataGrid以及针对DataGrid的数据邦定事件
/// </summary>
/// <param name="adg">DataGrid对象</param>
/// <param name="aBindData1">数据邦定事件</param>
public void SetTarget(DataGrid adg, BindDataDelegate aBindData1)
{
_dg = adg;
//BindData1 = new BindDataDelegate(aBindData1);
BindData1 = aBindData1; btnNavFirst.Click += new System.EventHandler(this.NavigationButtonClick);
btnNavPrevious.Click += new System.EventHandler(this.NavigationButtonClick);
btnNavNext.Click += new System.EventHandler(this.NavigationButtonClick);
btnNavLast.Click += new System.EventHandler(this.NavigationButtonClick);
btnNavGo.Click += new System.EventHandler(this.NavigationButtonClick);
_dg.DataBinding += new System.EventHandler(this.zxDataBinding);
} /// <summary>
/// 设置DataGrid样式
/// </summary>
/// <param name="aPageSize">每页显示行数</param>
/// <param name="aAutoHidden">是否自动隐藏</param>
/// <param name="aDispStyle">显示风格,1:标准型,2:精简型</param>
public void SetStyle(int aPageSize, bool aAutoHidden, int aDispStyle)
{
_pagesize = aPageSize;
_autohidden = aAutoHidden;//aAutoHidden;所有DataGrid都设置成自动隐藏
_dispStyle = aDispStyle; divPanel.Visible = !aAutoHidden; _dg.AllowPaging = true;
_dg.AllowCustomPaging = false;
_dg.PagerStyle.Visible = false;
_dg.PageSize = _pagesize;
_dg.PagerStyle.Mode = PagerMode.NumericPages;
_dg.PagerStyle.HorizontalAlign = HorizontalAlign.Right;
} public void SetStyle(int aPageSize, bool aAutoHidden)
{
SetStyle(aPageSize, aAutoHidden, 1);
} public void SetStyle(int aPageSize)
{
SetStyle(aPageSize, true);
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// 设计器支持所需的方法 - 不要使用
/// 代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion /// <summary>
/// 导航按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NavigationButtonClick(object sender, System.EventArgs e)
{
string direction = ((Button)sender).CommandName; switch (direction.ToUpper())
{
case "FIRST" :
_dg.CurrentPageIndex = 0;
break;
case "PREVIOUS" :
_dg.CurrentPageIndex =
Math.Max(_dg.CurrentPageIndex -1, 0);
break;
case "NEXT" :
_dg.CurrentPageIndex =
Math.Min(_dg.CurrentPageIndex + 1, _dg.PageCount - 1);
break;
case "LAST" :
_dg.CurrentPageIndex = Math.Max(_dg.PageCount - 1, 0);
break;
case "GO" :
try
{
_dg.CurrentPageIndex = Math.Min(_dg.PageCount - 1, int.Parse(tbPage.Text) - 1);
tbPage.Text = "";
}
catch
{
tbPage.Text = "";
}
break;
default :
break;
} BindData1();
} /// <summary>
/// DataGrid数据邦定前,设置导航条
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void zxDataBinding(object sender, System.EventArgs e)
{
int newCount = 0;
int PageCount = 0; if (_dg.DataSource == null)
{
SetButtonState(0);
return;
} if (_dg.DataSource.GetType().ToString().ToLower() == "system.data.datatable")
{
newCount = ((DataTable)_dg.DataSource).Rows.Count;
}
else if(_dg.DataSource.GetType().ToString().ToLower() == "system.data.dataview")
{
newCount = ((DataView)_dg.DataSource).Count;
}
else if(_dg.DataSource.GetType().ToString().ToLower() == "system.data.dataset")
{
newCount = ((DataSet)_dg.DataSource).Tables[0].Rows.Count;
} if(newCount > 0)
{
PageCount = (int)((newCount - 1) / _pagesize + 1);
if(_dg.CurrentPageIndex > PageCount - 1)_dg.CurrentPageIndex = PageCount - 1;
}
else
{
PageCount = 0;
_dg.CurrentPageIndex = 0;
}
switch (_dispStyle)
{
case 1:
LabelMsg.Text = "共" + PageCount.ToString() + "页 第" + (_dg.CurrentPageIndex + 1).ToString() + "页";
LabelMsg.Text += " 总记录数:" + newCount.ToString() + "";
break;
case 2:
LabelMsg.Text = (_dg.CurrentPageIndex + 1).ToString() + "/" + PageCount.ToString() + "页";
LabelMsg.Text += " 总数:" + newCount.ToString();
break;
} if (_autohidden)
{
divPanel.Visible = ((newCount - 1) / _pagesize > 0);
}
else
{
divPanel.Visible = true;
} SetButtonState(PageCount);
} /// <summary>
/// 设置导航按钮是否可用的状态
/// </summary>
/// <param name="_PageCount">总页数</param>
private void SetButtonState(int _PageCount)
{
btnNavFirst.Enabled = (_dg.CurrentPageIndex > 0);
btnNavPrevious.Enabled = (_dg.CurrentPageIndex > 0);
btnNavNext.Enabled = (_dg.CurrentPageIndex < _PageCount - 1);
btnNavLast.Enabled = (_dg.CurrentPageIndex < _PageCount - 1);
} }
}
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Drawing;namespace CdzDotNet
{
/// <summary>
/// DataGridNavigator 的摘要说明。
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:DataGridNavigator runat=server></{0}:DataGridNavigator>")]
public class DataGridNavigator : System.Web.UI.WebControls.WebControl
{ LinkButton LinkFirst = new LinkButton();
LinkButton LinkPreview = new LinkButton();
LinkButton LinkNext = new LinkButton();
LinkButton LinkLast = new LinkButton();
TextBox txtPageIndex = new TextBox();
Button btnGo = new Button();
TableRow row = new TableRow(); Label lblPageCount = new Label();
Label lblCurrentPage = new Label();
Label lblPageSize = new Label();
Label lblItemCount = new Label(); static private DataGrid _DataGrid;
static private DataSet _ds; protected override void CreateChildControls()
{
//AddChildControls();
} protected override void Render(HtmlTextWriter Writer)
{
//this.EnsureChildControls();
base.Render(Writer);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
// InitializeComponent();
base.OnInit(e);
AddChildControls();
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
LinkFirst.Click += new System.EventHandler(LinkButton_Click);
LinkPreview.Click += new System.EventHandler(LinkButton_Click);
LinkNext.Click += new System.EventHandler(LinkButton_Click);
LinkLast.Click += new System.EventHandler(LinkButton_Click); btnGo.Click += new System.EventHandler(btnGo_Click); }
#endregion public override Color ForeColor
{
get {return row.ForeColor;}
set {row.ForeColor = value;}
}
public string GotoText
{
get {return btnGo.Text;}
set {btnGo.Text = value;}
} public bool BoundDataGrid(DataGrid DataGridControl, DataSet ds)
{
_DataGrid = DataGridControl;
_ds = ds; if (null==_DataGrid) return false;
if (null==_ds) return false; _DataGrid.DataSource = _ds;
_DataGrid.DataBind();
InitControls(); return true;
} private bool BoundDataGrid()
{
if (_DataGrid==null || _ds==null) return false; if (!this.Page.IsPostBack)
{
_DataGrid.DataSource = _ds;
}
else
{
_DataGrid.DataSource = _ds.Tables[0].DefaultView;
}
//_DataGrid.CurrentPageIndex = 0;
_DataGrid.DataBind(); InitControls(); return true;
} private void InitControls()
{
lblItemCount.Text = _ds.Tables[0].Rows.Count.ToString();
lblCurrentPage.Text = Convert.ToString(_DataGrid.CurrentPageIndex+1);
lblPageSize.Text = _DataGrid.PageSize.ToString().Trim();
lblPageCount.Text = _DataGrid.PageCount.ToString().Trim(); LinkFirst.CommandName = "0";
LinkFirst.Enabled = _DataGrid.CurrentPageIndex > 0; LinkPreview.CommandName = Convert.ToString(_DataGrid.CurrentPageIndex - 1);
LinkPreview.Enabled = _DataGrid.CurrentPageIndex > 0; LinkNext.CommandName = Convert.ToString(_DataGrid.CurrentPageIndex + 1);
LinkNext.Enabled = _DataGrid.CurrentPageIndex < _DataGrid.PageCount - 1; LinkLast.CommandName = Convert.ToString(_DataGrid.PageCount - 1);
LinkLast.Enabled = _DataGrid.CurrentPageIndex < _DataGrid.PageCount - 1; } private void AddChildControls()
{
Controls.Clear(); Table table = new Table();
Controls.Add(table); table.Rows.Add(row);
TableCell cell;
LiteralControl labelText; cell = new TableCell();
cell.Wrap = false;
row.Cells.Add(cell);
labelText = new LiteralControl("共");
cell.Controls.Add(labelText);
lblItemCount.Text = "AC";
cell.Controls.Add(lblItemCount);
labelText = new LiteralControl("条");
cell.Controls.Add(labelText);
cell.Controls.Add(Emptylable()); cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(new LiteralControl("页次"));
cell.Controls.Add(lblCurrentPage);
lblCurrentPage.Text = "CP";
lblCurrentPage.ForeColor = System.Drawing.Color.Red;
cell.Controls.Add(new LiteralControl("/"));
cell.Controls.Add(lblPageCount);
lblPageCount.Text = "PC";
cell.Controls.Add(new LiteralControl("页"));
cell.Controls.Add(Emptylable());
row.Cells.Add(cell);
cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(lblPageSize);
lblPageSize.Text = "PS";
cell.Controls.Add(new LiteralControl("条/页"));
cell.Controls.Add(Emptylable());
row.Cells.Add(cell);
cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(LinkFirst);
LinkFirst.Text = "[首页]";
cell.Controls.Add(Emptylable());
row.Cells.Add(cell); cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(LinkPreview);
LinkPreview.Text = "[上一页]";
cell.Controls.Add(Emptylable());
row.Cells.Add(cell); cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(LinkNext);
LinkNext.Text = "[下一页]";
cell.Controls.Add(Emptylable());
row.Cells.Add(cell); cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(LinkLast);
LinkLast.Text = "[尾页]";
cell.Controls.Add(Emptylable());
row.Cells.Add(cell);
cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(new LiteralControl("转到第"));
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(txtPageIndex);
txtPageIndex.Width = Unit.Parse("30");
txtPageIndex.Height = Unit.Parse("20");
row.Cells.Add(cell); cell = new TableCell();
cell.Controls.Add(new LiteralControl("页"));
row.Cells.Add(cell); cell = new TableCell();
cell.Wrap = false;
cell.Controls.Add(Emptylable());
cell.Controls.Add(btnGo);
btnGo.Text = "GO"; row.Cells.Add(cell); } private LiteralControl Emptylable()
{
return new LiteralControl(" ");
} private void LinkButton_Click(object sender, System.EventArgs e)
{
if (_DataGrid == null) return;
_DataGrid.CurrentPageIndex = int.Parse(((LinkButton)sender).CommandName);
BoundDataGrid(_DataGrid, _ds);
} private void btnGo_Click(object sender, System.EventArgs e)
{
try
{
if (txtPageIndex.Text == "") return;
if (int.Parse(txtPageIndex.Text)-1 > _DataGrid.PageCount - 1) return;
if (int.Parse(txtPageIndex.Text)-1 < 0) return;
_DataGrid.CurrentPageIndex = int.Parse(txtPageIndex.Text) - 1;
BoundDataGrid(_DataGrid, _ds);
txtPageIndex.Text = ""; }
catch
{
}
}
}
}