下拉菜单跳转就是不能正确跳转!?
前一页后一页都是正常翻页 ,但是下拉菜单页面跳转,不跳转,选了还是会跳转到当前所在页。不知道咋回事,谢谢各位大虾了
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
private void Bind()
{
int cup = Convert.ToInt32(pagelbl.Text);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["temp"].ConnectionString);
PagedDataSource pds = new PagedDataSource();
SqlDataAdapter sda = new SqlDataAdapter("select * from main", con);
DataSet ds = new DataSet();
sda.Fill(ds,"tabe");
pds.DataSource = ds.Tables["tabe"].DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = 0;
pds.PageSize = 10;
DataList1.DataSource = pds;
pds.CurrentPageIndex = cup - 1;
if (!IsPostBack)
{//判断页面是否第一次载入
for (int i = 1; i <= pds.PageCount; i++)
{//循环出页码
pageddl.Items.Add(i.ToString());
}
}
//下面主要是控制上下翻页按纽是否起用
pageup.Enabled = true;
pagedown.Enabled = true;
if (pds.IsFirstPage)
{//如果是最前页,上页按纽不可用
pageup.Enabled = false;
}
if (pds.IsLastPage)
{//如果是最后页,下页按纽不可用
pagedown.Enabled = false;
}
//设置页码下拉菜单当前选中的值
pageddl.SelectedItem.Text = cup.ToString();
//终于可以绑定给DataList了
DataList1.DataSource = pds;
DataList1.DataKeyField = "id";
DataList1.DataBind();
}
protected void pageddl_SelectedIndexChanged(object sender, EventArgs e)
{//页码下拉菜单事件
pagelbl.Text = pageddl.SelectedItem.Text.ToString();
//pageddl.SelectedValue = pagelbl.Text;
Bind();
}
protected void pagedown_Click(object sender, EventArgs e)
{//下页事件
pagelbl.Text = Convert.ToString(Convert.ToInt32(pagelbl.Text) + 1);
Bind();
}
protected void pageup_Click(object sender, EventArgs e)
{//上页事件
pagelbl.Text = Convert.ToString(Convert.ToInt32(pagelbl.Text) - 1);
pageddl.SelectedValue = pagelbl.Text;
Bind();
}
}