日期:2014-05-17 浏览次数:20479 次
public partial class _Default : System.Web.UI.Page
{
DataClassesDataContext db = new DataClassesDataContext();
const string vsKey = "searchCriteria"; //ViewState key
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
searchOrders(string.Empty);
}
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
searchOrders((string)ViewState[vsKey]);
}
protected void Button1_Click(object sender, EventArgs e)
{
AspNetPager1.CurrentPageIndex = 1;
string s = "where word=" + TextBox1.Text;
ViewState[vsKey] = s;
searchOrders(s);
}
void searchOrders(string sWhere)
{
SqlDataSource1.SelectCommand = "select word from Table"+sWhere;
DataTable dv = (DataTable)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
// AspNetPager1.RecordCount = dv.Count;
AspNetPager1.RecordCount = db.Table.Count();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv.DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
}