在CrystalReports中,怎么在同一页上显示多条记录

newpant 2003-09-02 02:15:36
比如我有30条记录,我想每页显示5条,共有6页 :(

一定要帮帮我
...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
newpant 2003-09-04
  • 打赏
  • 举报
回复
大家帮帮忙...
newpant 2003-09-02
  • 打赏
  • 举报
回复
还是不太清楚,能否说得再详细些 :D thx
xjliang007 2003-09-02
  • 打赏
  • 举报
回复
其實很簡單,把要顯示的字段放在細目裡就可以一頁顯示多條記錄了,至於你說五條,可以通過控制行距和頁首頁尾高度等來控制了
XiaoCsharp 2003-09-02
  • 打赏
  • 举报
回复
直接指定各部分的高度,好象只有这个方法
xjliang007 2003-09-02
  • 打赏
  • 举报
回复
樓上的回答好象文不對題了。
XiaoCsharp 2003-09-02
  • 打赏
  • 举报
回复
CrystalReports,水晶表伙计,不是DataGrid
lemong 2003-09-02
  • 打赏
  • 举报
回复
分页使您可以按页段显示 DataGrid 控件的内容。页上的项数由 PageSize 属性确定。如果没有为 PageSize 属性指定任何值,则 DataGrid 将在一页上显示 10 项。

通常,在每次 DataGrid 控件移到不同页时都将加载包含 DataGrid 控件中每一行的数据源。当数据源很大时这会占用大量资源。自定义分页使您可以只加载显示单页所需的数据段。

若要启用自定义分页,请将 AllowPaging 和 AllowCustomPaging 属性都设置为 true。接下来,提供用来处理 PageIndexChanged 事件的代码。

PageIndexChanged 事件处理程序的典型逻辑是首先将 CurrentPageIndex 属性设置为您要显示的页的索引。

注意 事件处理程序接收 DataGridPageChangedEventArgs 对象作为参数。可以使用该参数的 NewPageIndex 属性来确定用户从 DataGrid 控件的页选择元素中所选择的页的索引。
接下来,创建包含要在单页显示的数据的数据源,然后使用 DataBind 方法将数据绑定到 DataGrid 控件。

注意 因为只加载一个数据段,所以您必须将 VirtualItemCount 属性设置为 DataGrid 控件中各项的总数。这使得该控件可以确定显示 DataGrid 控件中每一项所需的总页数。只要确定了 DataGrid 控件中的总项数,通常就可以用编程的方式设置此属性。
在通过将 AllowCustomPaging 属性设置为 false 来启用分页后,DataGrid 控件假设数据源包含所有要显示的项。DataGrid 控件根据 CurrentPageIndex 属性指定的页索引以及 PageSize 属性指定的页上项的数目来计算显示的页上各项的索引。

当 AllowCustomPaging 属性被设置为 true 时,DataGrid 控件假设数据源只包含由 VirtualItemCount 属性确定的项。所有项(项数最多可达由 PageSize 属性指定的数目)都将显示出来。

示例
下面的示例展示如何使用 AllowCustomPaging 属性来启用自定义分页。

[C#]
<%@ Import Namespace="System.Data" %>

<html>
<script language="C#" runat="server">

int start_index;

ICollection CreateDataSource()
{

DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

for (int i = start_index; i < start_index + ItemsGrid.PageSize; i++)
{
dr = dt.NewRow();

dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * (i+1);

dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

void Page_Load(Object sender, EventArgs e)
{

if (CheckBox1.Checked)
ItemsGrid.PagerStyle.Mode=PagerMode.NumericPages;
else
ItemsGrid.PagerStyle.Mode=PagerMode.NextPrev;

if (!IsPostBack)
{
start_index = 0;
ItemsGrid.VirtualItemCount=100;
}

BindGrid();

}

void Grid_Change(Object sender, DataGridPageChangedEventArgs e)
{

ItemsGrid.CurrentPageIndex = e.NewPageIndex;
start_index = ItemsGrid.CurrentPageIndex * ItemsGrid.PageSize;
BindGrid();

}

void BindGrid()
{

ItemsGrid.DataSource=CreateDataSource();
ItemsGrid.DataBind();

}

</script>

<body>

<form runat=server>

<h3>DataGrid Custom Paging Example</h3>

<asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
AllowPaging="true"
AllowCustomPaging="true"
AutoGenerateColumns="false"
OnPageIndexChanged="Grid_Change">

<PagerStyle NextPageText="Forward"
PrevPageText="Back"
Position="Bottom"
PageButtonCount="5"
BackColor="#00aaaa">
</PagerStyle>

<AlternatingItemStyle BackColor="yellow">
</AlternatingItemStyle>

<HeaderStyle BackColor="#00aaaa">
</HeaderStyle>

<Columns>

<asp:BoundColumn HeaderText="Number"
DataField="IntegerValue"/>

<asp:BoundColumn
HeaderText="Item"
DataField="StringValue"/>

<asp:BoundColumn
HeaderText="Price"
DataField="CurrencyValue"
DataFormatString="{0:c}">

<ItemStyle HorizontalAlign="right">
</ItemStyle>

</asp:BoundColumn>

</Columns>

</asp:DataGrid>

<br/>

<asp:CheckBox id="CheckBox1"
Text = "Show page navigation"
AutoPostBack="true"
runat="server"/>

</form>

</body>
</html>
要求
平台: Windows 2000, Windows XP Professional, Windows .NET Server family


110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧