资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
收藏功能问题收藏的 ALLItems 页面用了 Datalist 做;因此没有系统自带分页,只能自己写分页功能;#region 这是收藏后台代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Web.Common; using System.Data; using System.Data.SqlClient; using System.Configuration; namespace Web.Collections.UserControl public partial class WUCGrid : BasedUserControlprotected void Page_Load(object sender, EventArgs e)if (!IsPostBack)ViewState“pageindex“ = 0;BindData();private int _ArticleID;public int ArticleIDget return _ArticleID; set _ArticleID=value; protected void lnkBtnTitle_Click(object sender, EventArgs e)LinkButton lnkBtnTitle = (LinkButton)sender;if (lnkBtnTitle != null)ArticleID = Convert.ToInt32( lnkBtnTitle.CommandArgument);/查询对应的 ArticleID 的 ispublic 是否为 1;为公开;eSchool.JXKYW.Library.Articles articles = (from p in DataContext.Articleswhere p.ID.Equals(ArticleID) if (articles=null)throw new Exception(“文章已被删除!“);protected void dl_DataBinding(object sender, EventArgs e)/删除事件protected void dl_DeleteCommand(object source, DataListCommandEventArgs e)int Key = Convert.ToInt32(dl.DataKeyse.Item.ItemIndex.ToString();/获取激发 事件时的行的主键 IDString conString = ConfigurationManager.ConnectionStrings“JXKYWConnectionString“.ConnectionString;String strSql = “delete from Collections where ID=“ + Key + “;int rows = ExecuteSql(strSql, conString);BindData();public int ExecuteSql(string strSql,string conString)using (SqlConnection myConnection=new SqlConnection(conString)using (SqlCommand cmd=new SqlCommand(strSql, myConnection)myConnection.Open();int rows=cmd.ExecuteNonQuery();return rows;#region DataList 分页public static DataSet GetTable(string sql) SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings “JXKYWConnectionString“.ConnectionString); SqlDataAdapter da = new SqlDataAdapter(sql, conn);DataSet ds = new DataSet(); da.Fill(ds);return ds;public void BindData()string LoginName = this.CurrentLoginName;string sql = “select * from vw_CollectionsArticles where CollectorName=“+LoginName+“;DataSet objds = GetTable(sql);PagedDataSource objPds = new PagedDataSource();objPds.DataSource = objds.Tables0.DefaultView;objPds.AllowPaging = true;objPds.PageSize = 10;objPds.CurrentPageIndex = int.Parse(ViewState“pageindex“.ToString();if (!objPds.IsFirstPage)lkPre.Visible = true;elselkPre.Visible = false;if (!objPds.IsLastPage)lkNext.Visible = true;elselkNext.Visible = false;/如果没有找到数据就隐藏 pnlNoArticleif (objPds.DataSourceCount 0)this.FindControl(“pnlNoArticle“).Visible = false;elsethis.FindControl(“pnlNoArticle“).Visible = true;dl.DataSource = objPds;dl.DataKeyField = “ID“;dl.DataBind();/*上一页下一页的事件;I 两个按钮的 OnCommand 都是 IndexChanging()函数, 我们通过 CommandArgument(pre 和 next)来区分到底是向前翻还是向后翻。下面是 IndexChanging()函数*/protected void IndexChanging(object sender, EventArgs e)string strCommand = (LinkButton)sender).CommandArgument.ToString();/得到 linkbtn 的 CommandArgument 值int pageindex = int.Parse(ViewState“pageindex“.ToString();if (strCommand = “pre“)pageindex = pageindex - 1;elsepageindex = pageindex + 1;ViewState“pageindex“ = pageindex;BindData();#endregionprivate string _AuthorName;protected string AuthorNameget return _AuthorName; set _AuthorName = value; protected void hylArticleAuthor_Click(object sender, EventArgs e)LinkButton hylArticleAuthor=(LinkButton)sender;if(hylArticleAuthor!=null)AuthorName=hylArticleAuthor.Text.ToString();eSchool.JXKYW.Library.UserMappings UserMapping = (from p in DataContext.UserMappingswhere p.LoginName.Equals(AuthorName)select p).FirstOrDefault();if(UserMapping!=null)AnonymouEntityID = Convert.ToInt32(UserMapping.EntityID);AnonymouEntityType = “Contact“;Response.Redirect(“/PersonalDefault.aspx?Type=3“); #endregion#region 这是前台代码上一页 下一页收藏日期: /:标题: 25?(Eval(“ArticleTitle“).ToString().Substring(0,25):Eval(“ArticleTitle“) %OnClick=“lnkBtnTitle_Click“ CommandArgument=内容:35?(Eval(“ArticleContent“).ToString().Substring(0,35)+“.“:Eval(“ArticleContent“) %来自: 删除噢NO您还没有收藏过文章,赶快去收藏吧 #endregion一。以下是分页功能: #region DataList 分页public static DataSet GetDataSet(string sql)/得到数据集 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings “JXKYWConnectionString“.ConnectionString); SqlDataAdapter da = new SqlDataAdapter(sql, conn);DataSet ds = new DataSet(); da.Fill(ds);return ds;public void BindData()string LoginName = this.CurrentLoginName;/得到当前登录名;string sql = “select * from vw_CollectionsArticles where CollectorName=“+LoginName+“;DataSet objds = GetDataSet(sql);PagedDataSource objPds = new PagedDataSource();objPds.DataSource = objds.Tables0.DefaultView;/得到数据表;数据集的 第一个 Table;为默认数据源objPds.AllowPaging = true;/允许分页objPds.PageSize = 10;objPds.CurrentPageIndex = int.Parse(ViewState“pageindex“.ToString();/*CurrentPageIndex 获取或设置当前页的索引。用视图来保存 pageindex;没有视图时候给 0;在 page
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号