main_msg_list.aspx.cs
上传用户:woolgirl
上传日期:2020-04-18
资源大小:243k
文件大小:8k
- using System;
- using System.Data;
- using System.Data.OleDb;//ACCESS
- 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 Wuqi.Webdiyer;
- public partial class main_msg_list : System.Web.UI.Page
- {
-
- //conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("aspnetpager.mdb"));
- OleDbConnection conn = liuyinconn.connstr();
- OleDbCommand cmd;
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- string action = Request.QueryString["action"];
-
- if (action == "0")
- {
- cmd = new OleDbCommand("select count(yl_id) from yl_message WHERE yl_sh=0", conn);
- }
- else
- {
- cmd = new OleDbCommand("select count(yl_id) from yl_message WHERE yl_sh=1", conn);
- }
- try
- {
- conn.Open();//打开数据库链接 ;
- }
- catch
- {
- Response.Write("参数错误!");
- Response.End();
- }
-
-
- pager.RecordCount = (int)cmd.ExecuteScalar();
- conn.Close();
- BindData();
-
- //获取分页属性值
- /*
- psize.Items.FindByValue(pager.PageSize.ToString()).Selected = true;
- //获取导航按钮属性值
-
- bcount.Items.FindByValue(pager.NumericButtonCount.ToString()).Selected = true;
- showfl.Checked = pager.ShowFirstLast;
- showpn.Checked = pager.ShowPrevNext;
- showindex.Checked = pager.ShowPageIndex;
- cnindex.Checked = pager.ChinesePageIndex;
- showdb.Checked = pager.ShowDisabledButtons;
- bpadding.Text = pager.PagingButtonSpacing.ToString();
- bfstring.Text = pager.NumericButtonTextFormatString;
- fptext.Text = pager.FirstPageText;
- lptext.Text = pager.LastPageText;
- nptext.Text = pager.NextPageText;
- pptext.Text = pager.PrevPageText;
-
- //获取用户自定义信息区属性值
- cuswidth.Text = pager.CustomInfoSectionWidth.ToString();
- cusalign.Items.FindByValue(pager.CustomInfoTextAlign.ToString()).Selected = true;
- cusstyle.Text = pager.CustomInfoStyle;
- //获取文本框及提交按钮属性值
- showbox.Items[(int)pager.ShowInputBox].Selected = true;
- subtext.Text = pager.SubmitButtonText;
- txtbeforebox.Text = pager.TextBeforeInputBox;
- txtafterbox.Text = pager.TextAfterInputBox;
- boxstyle.Text = pager.InputBoxStyle;
- threshold.Text = pager.ShowBoxThreshold.ToString();
- //获取图片按钮属性值
- btntype.SelectedIndex = (pager.PagingButtonType == PagingButtonType.Text) ? 0 : 1;
- imgpath.Text = pager.ImagePath;
- imgext.Text = pager.ButtonImageExtension;
- imgnameext.Text = pager.ButtonImageNameExtension;
- cpinameext.Text = pager.CpiButtonImageNameExtension;
- disnameext.Text = pager.DisabledButtonImageNameExtension;
- */
- }
- }
- public void BindData()
- {
- string action = Request.QueryString["action"];
- string sql = "";
- if (action == "0")
- {
- sql = "SELECT yl_id,yl_title,yl_body,yl_name,yl_tel,yl_face,yl_adddate,yl_uid,yl_uidHF,yl_sh FROM yl_message WHERE yl_sh=0 ORDER BY yl_adddate DESC";
- }
- else
- {
- sql = "SELECT yl_id,yl_title,yl_body,yl_name,yl_tel,yl_face,yl_adddate,yl_uid,yl_uidHF,yl_sh FROM yl_message WHERE yl_sh=1 ORDER BY yl_adddate DESC";
- }
- cmd = new OleDbCommand(sql, conn);
- OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
- DataSet rs = new DataSet(); // 生成DataSet对象并填充数据
- adapter.Fill(rs, pager.PageSize * (pager.CurrentPageIndex - 1), pager.PageSize, "msg"); // 将Repeater控件进行数据绑定
- repeater.DataSource = rs.Tables["msg"];
- repeater.DataBind();
- //获取并显示分页信息
- cindex.Text = pager.CurrentPageIndex.ToString();
- rcount.Text = pager.RecordCount.ToString();
- pcount.Text = pager.PageCount.ToString();
- pagesize.Text = pager.PageSize.ToString();
- pagesleft.Text = pager.PagesRemain.ToString();
- recordsleft.Text = pager.RecordsRemain.ToString();
-
- //动态设置用户自定义文本内容
- //pager.CustomInfoText = "记录总数:<font color="blue"><b>" + pager.RecordCount.ToString() + "</b></font>";
- // pager.CustomInfoText += " 总页数:<font color="blue"><b>" + pager.PageCount.ToString() + "</b></font>";
- // pager.CustomInfoText += " 当前页:<font color="red"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";
- // showisec.SelectedIndex = (int)pager.ShowCustomInfoSection;
- conn.Close();
- }
- public void ChangePage(object src, PageChangedEventArgs e)
- {
- pager.CurrentPageIndex = e.NewPageIndex;
- BindData();
- }
- public void ChangePagerProperties(object src, EventArgs e)
- {
- /*
- //设置分页属性值
- pager.PageSize = int.Parse(psize.SelectedItem.Value);
- //设置导航按钮属性值
- pager.NumericButtonCount = int.Parse(bcount.SelectedItem.Value);
- pager.ShowFirstLast = showfl.Checked;
- pager.ShowPrevNext = showpn.Checked;
- pager.ShowPageIndex = showindex.Checked;
- if (!IsInputEmpty(fptext.Text))
- pager.FirstPageText = fptext.Text;
- if (!IsInputEmpty(lptext.Text))
- pager.LastPageText = lptext.Text;
- if (!IsInputEmpty(pptext.Text))
- pager.PrevPageText = pptext.Text;
- if (!IsInputEmpty(nptext.Text))
- pager.NextPageText = nptext.Text;
- pager.ChinesePageIndex = cnindex.Checked;
- pager.ShowDisabledButtons = showdb.Checked;
- pager.PagingButtonSpacing = Unit.Parse(bpadding.Text);
- pager.NumericButtonTextFormatString = bfstring.Text;
- //设置文本框及提交按钮属性值
- pager.ShowInputBox = (ShowInputBox)Enum.Parse(typeof(ShowInputBox), showbox.SelectedItem.Value);
- pager.SubmitButtonText = subtext.Text;
- pager.TextBeforeInputBox = txtbeforebox.Text;
- pager.TextAfterInputBox = txtafterbox.Text;
- pager.ShowBoxThreshold = int.Parse(threshold.Text.Trim());
- //设置图片按钮属性值
- pager.PagingButtonType = (PagingButtonType)Enum.Parse(typeof(PagingButtonType), btntype.SelectedItem.Value);
- //设置用户自定义文本区属性值
- pager.HorizontalAlign = (showisec.SelectedIndex == 2) ? HorizontalAlign.Left : HorizontalAlign.Right;
- pager.ShowCustomInfoSection = (ShowCustomInfoSection)Enum.Parse(typeof(ShowCustomInfoSection), showisec.SelectedItem.Value);
- pager.CustomInfoSectionWidth = Unit.Parse(cuswidth.Text.Trim());
- pager.CustomInfoTextAlign = (HorizontalAlign)Enum.Parse(typeof(HorizontalAlign), cusalign.SelectedItem.Value);
- pager.CustomInfoStyle = cusstyle.Text;
- BindData();
- */
- }
- bool IsInputEmpty(string input)
- {
- if (input.Trim().Length > 0)
- return false;
- return true;
- }
- //计算总共有多少条记录
- public int CalculateRecord()
- {
- int intCount;
- OleDbConnection conn = liuyinconn.connstr();
- conn.Open();//打开数据库链接 ;
- string strCount = "select count(*) as yl_id from yl_message";
- OleDbCommand MyComm = new OleDbCommand(strCount, conn);
- OleDbDataReader rs = MyComm.ExecuteReader();
- if (rs.Read())
- {
- intCount = Int32.Parse(rs["yl_id"].ToString());
- }
- else
- {
- intCount = 0;
- }
- rs.Close();
- conn.Close();
- return intCount;
- }
- }