DataGrid分页显示相关问题,巨easy

lonelydreamsym 2004-11-10 12:04:43
DataGrid分页时,<PagerStyle HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>
以数字形式在右边显示分页,我想在显示分页数字的行的左边显示一些文字信息,怎么实现,要与显示分页数字同行,不同行的不算
...全文
248 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lonelydreamsym 2004-11-11
  • 打赏
  • 举报
回复
自己顶一下
berlin8600 2004-11-11
  • 打赏
  • 举报
回复
同意colinliu(流浪人) ,应该自已写。看看这个程序适合你说的情况不,自已改改看。
<%@ Page Debug="true" Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<head>
<title>自定义DataGrid的导航控件</title>
<script language="C#" runat="server" >

// This data container will be initialize when Page is loaded
DataTable dataTable;

public void Page_Load()
{
string dataSource = "Data Source=localhost;";
string security = "user id=sa; password=;";
string initialCatalog = "initial catalog=pubs;";
string cnnString = dataSource + security + initialCatalog;
SqlConnection connection = new SqlConnection(cnnString);

string strSql = "select au_lname, au_fname, city, state, zip from [authors]";
SqlCommand command = new SqlCommand(strSql, connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
dataTable = new DataTable();

try {
connection.Open();
adapter.Fill(dataTable);
}
catch(SqlException e) {
Response.Write(e.ToString());
return;
}
finally {
connection.Close();
}

if(!IsPostBack)
{
grid1.DataSource = dataTable;
grid1.DataBind();
lblTotalNumber.Text = grid1.PageCount.ToString();
txtPage.Text = grid1.CurrentPageIndex.ToString();
}
}

public void NextPrevPage(object sender, EventArgs e)
{
if(((LinkButton)sender).ID == "PrevButton")
{
if(grid1.CurrentPageIndex != 0)
grid1.CurrentPageIndex --;
}
else
{
if(grid1.CurrentPageIndex != grid1.PageCount-1)
grid1.CurrentPageIndex++;
}
grid1.DataSource = dataTable;
grid1.DataBind();
txtPage.Text = grid1.CurrentPageIndex.ToString();
}

public void JumpToPage(object sender, EventArgs e)
{
int number = 0;
try {
number = int.Parse(txtPage.Text);
}
catch { return; }

if(number < 0 || number > grid1.PageCount-1)
{
txtPage.Text = grid1.CurrentPageIndex.ToString();
return;
}
grid1.CurrentPageIndex = number;
grid1.DataSource = dataTable;
grid1.DataBind();
}
</script>
</head>

<body>
<form id="form1" runat="server">
<h3>自定义DataGrid的导航控件</h3>
<asp:DataGrid id="grid1" runat="server" AllowPaging="true" PageSize="5">
<HeaderStyle BackColor="lightblue" Font-Name="Arial" Font-Bold="true" />
<ItemStyle BackColor="lightyellow"/>
<PagerStyle Visible="false" />
</asp:DataGrid>
<asp:LinkButton Text="上一页" id="PrevButton"
OnClick="NextPrevPage" runat="server" />
<asp:LinkButton Text="下一页" id="NextButton"
OnClick="NextPrevPage" runat="server" />
 跳转到 <asp:TextBox id="txtPage" width="20pt"
OnTextChanged="JumpToPage" AutoPostBack="true" runat="server"/>页,
 总共<asp:Label id="lblTotalNumber" runat="server"/>页

</form>
</body>
</html>
pkkingofice 2004-11-11
  • 打赏
  • 举报
回复
我也想知道,用力顶
codeyyh 2004-11-11
  • 打赏
  • 举报
回复
用AspxGrid啊
colinliu 2004-11-11
  • 打赏
  • 举报
回复
顯示文字的話,要自己寫的的,本身不支持文字
lonelydreamsym 2004-11-11
  • 打赏
  • 举报
回复
怎么没人回呢,是不是分太少呢??
sunshine5211314 2004-11-10
  • 打赏
  • 举报
回复
用ItemCreated事件中加入
{
if(e.Item.ItemType==ListItemType.Pager)
//加入代码
}
  • 打赏
  • 举报
回复
关注
lonelydreamsym 2004-11-10
  • 打赏
  • 举报
回复
哪位给指点一下呀
wjcking 2004-11-10
  • 打赏
  • 举报
回复
.l
lonelydreamsym 2004-11-10
  • 打赏
  • 举报
回复
不太明白

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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