1.asp.net如何实现gridview控件进行分页并带有查询的分页分页代码
2.C# GridView åç» å¦ä½å®ç°ï¼
asp.net如何实现gridview控件进行分页并带有查询的代码
.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()函数你能不能自己写?就是连接数据库,把查询出来的源码集成源码zlib结果放到一个DataTable对象中,然后函数返回值就是显示fabric源码安装这个DataTable对象。
C# GridView åç» å¦ä½å®ç°ï¼
æ£å·§æåè¿ç±»ä¼¼çä¸ä¸ªæµè¯ï¼å¯ä»¥å¸®å©ä½ ä¸é¦å ä½ è¦äºè§£bindingSource å bindingNavigator æ§ä»¶ã
è¿éæ说çæ¯ä¸å©ç¨ç¬¬ä¸æ¹çå页æ§ä»¶ã
é ç½®å¦ä¸
m_cardDataSet.Tables[0]å¨æä¸è¡¨ç¤ºä¸ºå次æ¥è¯¢åºæ¥çææç»æä¿¡æ¯
ç»ä½ æä¾æåç两个å½æ°
int pageSize = ;//æ¯é¡µæ¾ç¤ºçè¡æ°
int nMax = 0;//æ»è®°å½æ°
int pageCount = 0;//页æ°
int pageCurrent = 0;//å½å页å·
int nCurrent = 0;//å½åè¡å·
//åå§åå页信æ¯-æ ¹æ®ä¼ éçtable表信æ¯
public void InitDataTable(DataTable p_dataTable)
{
nMax = p_dataTable.Rows.Count;
pageCount = (nMax / pageSize);
if (nMax % pageSize > 0)
{
pageCount++;
}
pageCurrent = 1;
nCurrent = 0;
LoadData(p_dataTable);
}
//å è½½å页信æ¯å°é¡µé¢ä¸
public void LoadData(DataTable p_dataTable)
{
int nStartPos = 0;
int nEndPos = 0;
DataTable deTemp = new DataTable();
deTemp = p_dataTable.Clone();
if (pageCurrent == pageCount)
{
nEndPos = nMax;
}
else
{
nEndPos = pageSize * pageCurrent;
}
nStartPos = nCurrent;
pageCountNumber.Text = "å ±" + pageCount.ToString() + "页";
currentPage.Text = "第" + Convert.ToString(pageCurrent) + "页";
if (p_dataTable.Rows.Count > 0)
{
for (int i = nStartPos; i < nEndPos; i++)
{
deTemp.ImportRow(p_dataTable.Rows[i]);
nCurrent++;
}
}
bdsInfo.DataSource = deTemp;
bdnInfo.BindingSource = bdsInfo;
carDataDgv.DataSource = bdsInfo;
}
//bindingNavigator ç»å®çå½æ°
private void bdnInfo_ItemClicked(object sender,分页分页android学校源码 ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "ä¸ä¸é¡µ")
{
pageCurrent--;
if (pageCurrent <= 0)
{
MessageBox.Show("å·²ç»æ¯ç¬¬ä¸é¡µ,请ç¹å»ä¸ä¸é¡µ!");
return;
}
else
{
nCurrent = pageSize * (pageCurrent - 1);
}
LoadData(m_cardDataSet.Tables[0]);
}
if (e.ClickedItem.Text == "ä¸ä¸é¡µ")
{
pageCurrent++;
if (pageCurrent > pageCount)
{
MessageBox.Show("å·²ç»æ¯æåä¸é¡µ,请ç¹å»ä¸ä¸é¡µ!");
return;
}
else
{
nCurrent = pageSize * (pageCurrent - 1);
}
LoadData(m_cardDataSet.Tables[0]);
}
if (e.ClickedItem.Text == "é¦é¡µ")
{
pageCurrent=1;
nCurrent = pageSize * (pageCurrent - 1);
LoadData(m_cardDataSet.Tables[0]);
}
if (e.ClickedItem.Text == "尾页")
{
pageCurrent = pageCount;
if (pageCurrent > 0)
{
nCurrent = pageSize * (pageCurrent - 1);
}
else
{
nCurrent = 0;
}
LoadData(m_cardDataSet.Tables[0]);
}
}