using System; using System.Data; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using fiveXdotNet.BLL;
namespace fiveXdotNet.Web { /// <summary> /// index 的摘要说明。 /// </summary> public class index : ScrollPage { protected System.Web.UI.WebControls.Label lblName; protected System.Web.UI.WebControls.Label lblPostId; protected System.Web.UI.WebControls.Label lblPostTime; protected System.Web.UI.WebControls.Label lblContent; protected System.Web.UI.WebControls.Label lblPosterName; protected System.Web.UI.WebControls.Label lblReplyTime; protected System.Web.UI.WebControls.Label lblReplyContent; protected System.Web.UI.WebControls.DataGrid dgPostList; protected System.Web.UI.WebControls.DataList dlReplyList; protected System.Web.UI.HtmlControls.HtmlTextArea txaNewPost; protected DataSet _ds = new DataSet(); private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack){ bind(); } //string s = this.Request.Form["txaNewPost"]; //string s01 = this.Request.Form["txt01"]; //string s02 = this.Request.Form["txaNewPost"]; }
private void bind(){ Post.getAllPost(ref _ds); DataView dvPostList = new DataView(_ds.Tables[0], "PostType = 0","PostID desc",DataViewRowState.CurrentRows); dgPostList.DataSource = dvPostList; dgPostList.DataBind(); } protected DataView GetReplyData(int iPostId){ DataView dvPostList = new DataView(_ds.Tables[0],"PostType = " + iPostId.ToString(),"PostID",DataViewRowState.CurrentRows); //DataView dvPostList = new DataView(_ds.Tables[0]); //dvPostList.RowFilter = "PostType = " + iPostId.ToString(); return dvPostList; }
protected void TrunPage(object sender, DataGridPageChangedEventArgs e){ dgPostList.CurrentPageIndex = e.NewPageIndex; dgPostList.EditItemIndex = -1; this.bind(); } protected void EditReply(object sender, System.Web.UI.WebControls.DataListCommandEventArgs e){ DataList dlReplyList = (DataList)sender; dlReplyList.EditItemIndex = e.Item.ItemIndex; dgPostList.EditItemIndex = -1; DataGridItem dgi = (DataGridItem)dlReplyList.Parent.Parent; int n = dgi.ItemIndex; int nPostID = (int)dgPostList.DataKeys[n]; Post.getAllPost(ref _ds); dlReplyList.DataSource = GetReplyData(nPostID); dlReplyList.DataBind(); //dl.DataBind(); //dlReplyList.EditItemIndex = e.Item.ItemIndex; //this.dlReplyList = dl; //Post.getAllPost(ref _ds); //this.dlReplyList.DataSource = GetReplyData(22); //this.dlReplyList.DataBind(); //this.bind(); } protected void EditPost(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e){ dgPostList.EditItemIndex = e.Item.ItemIndex; this.bind(); } protected void AddPost(object sender, System.Web.UI.ImageClickEventArgs e){ //string sContent = this.txaNewPost.Value.ToString();//为什么用编程方式取不到值的? string sContent = this.Request.Form["txaNewPost"]; //Session["ClassmateId"] = 1; Post post = new Post(Convert.ToInt32(Session["ClassmateId"]), DateTime.Now, 0, sContent); post.Add(); this.bind(); } public void DeletePost(object sender, DataGridCommandEventArgs e) { int iPostId = Convert.ToInt32(dgPostList.DataKeys[(int)e.Item.ItemIndex]); Post.Delete(iPostId); this.bind(); } public void DeleteReply(object sender, DataListCommandEventArgs e) { int iPostId = Convert.ToInt32(dlReplyList.DataKeys[(int)e.Item.ItemIndex]); Post.Delete(iPostId); this.bind(); } public void UpdatePost(object sender, DataGridCommandEventArgs e) { int iPostId = Convert.ToInt32(dgPostList.DataKeys[(int)e.Item.ItemIndex]); string sContent = ((TextBox)e.Item.FindControl("txtPostContent")).Text; DateTime dtPostTime = DateTime.Now; Post post = new Post(iPostId, dtPostTime, sContent); post.Update(); dgPostList.EditItemIndex = -1; this.bind(); }
public void UpdateReply(object sender, DataListCommandEventArgs e) { int iPostId = Convert.ToInt32(dlReplyList.DataKeys[(int)e.Item.ItemIndex]); string sContent = ((TextBox)e.Item.FindControl("txtReplyConten")).Text; DateTime dtPostTime = DateTime.Now; Post post = new Post(iPostId, dtPostTime, sContent); post.Update(); dlReplyList.EditItemIndex = -1; this.bind(); }
public void CancelPost(object sender, DataGridCommandEventArgs e) { dgPostList.EditItemIndex = -1; this.bind(); } public void CancelReply(object sender, DataListCommandEventArgs e) { dlReplyList.EditItemIndex = -1; this.bind(); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load);
} #endregion } }
|