asp.net如何实现gridview控件进行分页并带有查询的代码 15
asp.net如何实现gridview控件当前多少页共多少页,首页,上一页,下一页,尾页,跳转及分页查询功能,如图所示一定要有分页且带有查询功能效果的代码,而且仅仅使用s...
asp.net如何实现gridview控件当前多少页共多少页,首页,上一页,下一页,尾页,跳转及分页查询功能,如图所示
一定要有分页且带有查询功能效果的代码,而且仅仅使用select查询语句,不涉及到Linq等技术也就是只能用Select查询语句编写的代码 展开
一定要有分页且带有查询功能效果的代码,而且仅仅使用select查询语句,不涉及到Linq等技术也就是只能用Select查询语句编写的代码 展开
2个回答
展开全部
.aspx文件中的代码(格式你自己调):
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:LinkButton ID="lnkbtnFrist" runat="server" OnClick="lnkbtnFrist_Click">首页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnPre" runat="server" OnClick="lnkbtnPre_Click">上一页</asp:LinkButton>
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
<asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnLast" runat="server" OnClick="lnkbtnLast_Click">尾页</asp:LinkButton>
跳转到第<asp:DropDownList ID="ddlCurrentPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>页
.aspx.cs文件中的代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
bind();
}
protected void lnkbtnFrist_Click(object sender, EventArgs e)
{
this.GridView1.PageIndex = 0;
bind();
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
if (this.GridView1.PageIndex > 0)
{
this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
bind();
}
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
if (this.GridView1.PageIndex < this.GridView1.PageCount)
{
this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
bind();
}
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
this.GridView1.PageIndex = this.GridView1.PageCount;
bind();
}
public void bind()
{
GridView1.DataSource = getData();
GridView1.DataKeyNames = new string[] { "学号" };
GridView1.DataBind();
this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GridView1.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
}
getdata()函数你能不能自己写?就是连接数据库,把查询出来的结果放到一个DataTable对象中,然后函数返回值就是这个DataTable对象。
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:LinkButton ID="lnkbtnFrist" runat="server" OnClick="lnkbtnFrist_Click">首页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnPre" runat="server" OnClick="lnkbtnPre_Click">上一页</asp:LinkButton>
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
<asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnLast" runat="server" OnClick="lnkbtnLast_Click">尾页</asp:LinkButton>
跳转到第<asp:DropDownList ID="ddlCurrentPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>页
.aspx.cs文件中的代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
bind();
}
protected void lnkbtnFrist_Click(object sender, EventArgs e)
{
this.GridView1.PageIndex = 0;
bind();
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
if (this.GridView1.PageIndex > 0)
{
this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
bind();
}
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
if (this.GridView1.PageIndex < this.GridView1.PageCount)
{
this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
bind();
}
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
this.GridView1.PageIndex = this.GridView1.PageCount;
bind();
}
public void bind()
{
GridView1.DataSource = getData();
GridView1.DataKeyNames = new string[] { "学号" };
GridView1.DataBind();
this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GridView1.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
}
getdata()函数你能不能自己写?就是连接数据库,把查询出来的结果放到一个DataTable对象中,然后函数返回值就是这个DataTable对象。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分页控件你用哪个?aspnetpager?
更多追问追答
追问
我自己编写的一个没有用那个控件,不过你要是能用aspnetpager能编写出来了也行,不过只能用select语句不涉及linq,mvc等,要是有相关代码,请发一个我参考参考!!!
追答
那gridview不是自带分页功能的吗,指定sqldata数据源就可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询