private void Page_Load(object sender, System.EventArgs e)
{
this.btn_delete.Attributes["onClick"]="if(!confirm('确定要删除吗?')) return false;";
if(!this.IsPostBack)
{
ViewState["PageIndex"]=1;
this.BrushPageCount();
}
try
{
int page=Convert.ToInt32(ViewState["PageIndex"].ToString());
string strWhere="BULLETIN=''Y''";
string strSql="exec search_sp 'NET_BULLETINTB','BULLETINID,BULLETINTITLE,Bulletintime','BULLETINID',20,"+page+",0,1,'"+strWhere+"'";
SqlDataAdapter adapter=new SqlDataAdapter(strSql,TpsClass.ConnectionString());
DataSet ds=new DataSet();
adapter.Fill(ds,"NET_BULLETINTB");
this.dg_gonggao.DataSource = ds.Tables[0];
if(!this.IsPostBack)
this.dg_gonggao.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
log.Error(ex.Message);
}
this.ShowPosition();
}
private void BrushPageCount()
{
int pageSize=20;
int pageCount=0;
int count=0;
SqlConnection conn=new SqlConnection(TpsClass.ConnectionString());
string strWhere="BULLETIN='Y'";
string sql="select Count(BULLETINID) as id from NET_BULLETINTB where "+strWhere;
SqlCommand com = new SqlCommand(sql,conn);
conn.Open();
SqlDataReader rd=com.ExecuteReader();
while(rd.Read())
{
count=Convert.ToInt32(rd[0].ToString());
}
rd.Close();
conn.Close();
if(count!=0)
{
if(count%pageSize==0)
{
pageCount=count/pageSize;
}
else
{
pageCount=count/pageSize+1;
}
}
else
pageCount=1;
ViewState["PageCount"]=pageCount;
ViewState["PageIndex"]=1;
}
#region
private void ShowPosition()
{
this.lb_current.Text=string.Format("{0}/{1}",ViewState["PageIndex"].ToString(),ViewState["PageCount"].ToString());
}
private void lb_first_Click(object sender, System.EventArgs e)
{
ViewState["PageIndex"]=1;
this.BindList();
this.ShowPosition();
}
private void lb_last_Click(object sender, System.EventArgs e)
{
ViewState["PageIndex"]=ViewState["PageCount"].ToString();
this.BindList();
this.ShowPosition();
}
private void lb_next_Click(object sender, System.EventArgs e)
{
if(ViewState["PageIndex"].ToString()!=ViewState["PageCount"].ToString())
{
ViewState["PageIndex"]=Convert.ToInt64(ViewState["PageIndex"].ToString())+1;
this.BindList();
this.ShowPosition();
}
}
private void lb_pre_Click(object sender, System.EventArgs e)
{
if(ViewState["PageIndex"].ToString()!="1")
{
ViewState["PageIndex"]=Convert.ToInt64(ViewState["PageIndex"].ToString())-1;
this.BindList();
this.ShowPosition();
}
}
#endregion