简单新闻管理系统v适合.net初学者

时间:2012-04-24 16:28:51
【文件属性】:

文件名称:简单新闻管理系统v适合.net初学者

文件大小:912KB

文件格式:RAR

更新时间:2012-04-24 16:28:51

新闻管理

using System; using System.Data; using System.Data.SqlClient; using System.Configuration; 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; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { LoginAcc.LoginCheck(); if (!Page.IsPostBack) { DataBind(); } } void DataBind() { //string str = "select NewsId,Title,AddTime,ViewCounter from ViewTable order by AddTime desc"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("up_GetDetilNews", conn); cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds,"result"); GridView1.DataSource = ds.Tables["result"]; GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { //GridView1.PageIndex = e.NewPageIndex; GridView theGrid = sender as GridView; // refer to the GridView int newPageIndex = 0; if (-2 == e.NewPageIndex) { // when click the "GO" Button TextBox txtNewPageIndex = null; //GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow //updated at 2006年6月21日3:15:33 if (null != pagerRow) { txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value } if (null != txtNewPageIndex) { newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex } } else { // when click the first, last, previous and next Button newPageIndex = e.NewPageIndex; } // check to prevent form the NewPageIndex out of the range newPageIndex = newPageIndex < 0 ? 0 : newPageIndex; newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex; // specify the NewPageIndex theGrid.PageIndex = newPageIndex; // rebind the control // in this case of retrieving the data using the xxxDataSoucr control, // just do nothing, because the asp.net engine binds the data automatically // 别忘了重新绑定 DataBind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strId = (GridView1.DataKeys[e.RowIndex].Value).ToString(); string delStr = "delete from ViewTable where NewsId=" + strId; DbUtil.DbHelper.ExecSqlNonQuerry(delStr); DataBind(); MyUtil.CsHelper.ExecJS("删除成功!", this); } }


网友评论

  • 代码不是很完善
  • 可以运行,不过确实太“简单了”。
  • 挺不错的 很用用
  • 可以 自己再修改了下 看着很好
  • 挺不错的 我同学看了都说好
  • 不错的资源~但是代码不是很完善哦~~
  • 不错的资源~但是代码不是很完善哦~~