?? forum.aspx.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 + -