⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forum.aspx.cs

📁 asp做的新闻系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Web.Admin
{
	/// <summary>
	/// Forum 的摘要说明。
	/// </summary>
	public class Forum : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Panel Panel2;
		protected System.Web.UI.WebControls.ImageButton Imagebutton1;
		protected System.Web.UI.WebControls.TextBox Textbox7;
		protected System.Web.UI.WebControls.Label LabID;
		protected System.Web.UI.WebControls.Label LabRowID;
		protected System.Web.UI.WebControls.Label LabRowCount;
		protected System.Web.UI.WebControls.Button BtnDel;
		protected System.Web.UI.WebControls.DataGrid GrdForum;
		protected System.Web.UI.HtmlControls.HtmlTable Table1;
	
		private DataSet OleDs;
		private Web.DataAccess.DataAccess Das = new DataAccess.DataAccess();
		protected System.Web.UI.WebControls.DropDownList DropForum;
		const int nGrdRows = 10;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{ 
				BindGrdForum(1);
			}

			GrdForum.Attributes.Add("onclick","javascript:Click('GrdForum');");
			BtnDel.Attributes.Add("OnClick","javascript:return Del('GrdForum');");
		}

		//刷新GrdForum
		private void BindGrdForum(int nForumID)
		{

			OleDs = new DataSet();

			OleDs=Das.GetDataSet("select boardid,title,username,postdate from forum where forumid = " + nForumID + " and replyboardid=0");
			GrdForum.DataSource=OleDs;
			
			int nPage=0;
			nPage = GrdForum.CurrentPageIndex;
			GrdForum.CurrentPageIndex = 0;
			GrdForum.DataBind();

			if ((nPage >= GrdForum.PageCount) && (GrdForum.PageCount > 0))
			{
				nPage = GrdForum.PageCount - 1;
			}
			
			LabRowCount.Text=OleDs.Tables[0].Rows.Count.ToString();

			GrdForum.CurrentPageIndex = nPage;
			GrdForum.DataBind();
		}

		//检查用户选择DataGrid中记录的总数,返回DG中单选的记录号,多选的记录号保存LabDeptID中。
		private int CheckCbx()
		{
			int nRow = -1;
			LabID.Text = "";
			for (int i = 0;i < GrdForum.Items.Count;i++)
			{
				CheckBox CbxTable = (CheckBox)GrdForum.Items[i].FindControl("CbxSelect");
				if(CbxTable.Checked == true)
				{
					if(LabID.Text == "")
					{
						LabID.Text = GrdForum.Items[i].Cells[4].Text.Trim();
						nRow = i;
					}
					else
					{
						LabID.Text = LabID.Text + "," + GrdForum.Items[i].Cells[4].Text.Trim();
					}
				}
			}
			return nRow;
		}

		//换页
		private void GrdForum_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			GrdForum.CurrentPageIndex = e.NewPageIndex;
			BindGrdForum(int.Parse(DropForum.SelectedItem.Value.ToString()));
		}

		//排序
		private void GrdForum_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
		{
			DataView dv = new DataView();
			BindGrdForum(int.Parse(DropForum.SelectedItem.Value.ToString()));
			dv.Table = OleDs.Tables[0];
			dv.Sort = e.SortExpression;
			GrdForum.DataSource = dv;
			GrdForum.DataBind();
			GrdForum.EditItemIndex = -1;
			GrdForum.SelectedIndex = 0;
		}

		//删除信息
		private void BtnDel_Click(object sender, System.EventArgs e)
		{
			int nRow = 0;
			string strTableID,strSql;

			nRow = CheckCbx();
			strTableID = LabID.Text.Trim();

			strSql = "delete from forum where boardid in(" + strTableID + ")";

			if (Das.ExecSql(strSql))
			{
				Response.Write("<script>alert('删除成功!');</script>");
				BindGrdForum(int.Parse(DropForum.SelectedItem.Value.ToString()));
			}
			else
			{
				Response.Write("<script>alert('删除不成功,请稍后再试!');</script>");
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.DropForum.SelectedIndexChanged += new System.EventHandler(this.DropForum_SelectedIndexChanged);
			this.BtnDel.Click += new System.EventHandler(this.BtnDel_Click);
			this.GrdForum.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.GrdForum_PageIndexChanged);
			this.GrdForum.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.GrdForum_SortCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void DropForum_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			BindGrdForum(int.Parse(DropForum.SelectedItem.Value.ToString()));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -