gridview分页(如何把分页模板设为隐藏)
//分页protected void pageindex()
{
try
{
SqlConnection mysqlconn = new SqlConnection(publicclass.getconnstr());
mysqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from UF_POST", mysqlconn);
DataSet ds = new DataSet();
sda.Fill(ds, "UF_POST");
GridView1.DataSource = ds.Tables["UF_POST"];
GridView1.AllowPaging = true;
GridView1.PageSize = 10;
GridView1.DataBind();
shou.Enabled = true;
shang.Enabled = true;
xia.Enabled = true;
wei.Enabled = true;
if (GridView1.PageIndex == 0)
{
shou.Enabled = false;
shang.Enabled = false;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
xia.Enabled = false;
wei.Enabled = false;
}
if (!IsPostBack)
{
for (int i = 0; i < GridView1.PageCount; i++)
{
DropDownList1.Items.Add(i.ToString());
}
}
Label1.Text = GridView1.PageCount.ToString();
Label2.Text = GridView1.PageSize.ToString();
Label3.Text = GridView1.PageIndex.ToString();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
//首页
protected void shou_Click(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
pageindex();
}
//上一页
protected void shang_Click(object sender, EventArgs e)
{
GridView1.PageIndex = GridView1.PageIndex - 1;
pageindex();
}
//下一页
protected void xia_Click(object sender, EventArgs e)
{
GridView1.PageIndex = GridView1.PageIndex + 1;
pageindex();
}
//尾页
protected void wei_Click(object sender, EventArgs e)
{
GridView1.PageIndex = GridView1.PageCount - 1;
pageindex();
}
//跳转
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageIndex = Convert.ToInt32(DropDownList2.SelectedItem.Text);
Label3.Text = DropDownList2.Text;
pageindex();
}