简单新闻管理系统v适合.net初学者
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); } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 粉丝: 1
- 资源: 1
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 1美赛大纲资料.txt
- 2011-2020各省房地产业增加值-亿元
- 无外观自定义控件Demo
- 基于java与阿里云RDS数据库对于天天基金网上的基金公告进行爬取与查询.zip
- Unity3D((4.x5.x)版本游戏源码(4.x-5.x)横板跑酷游戏
- 毕业设计基于LabView+MATLAB的说话人识别系统源码+说明.zip
- 基于LabVIEW的音乐机器人源码课程设计.zip
- SaveShareFileSet(保存WINDOWS server所有共享用户,共享文件夹,和共享权限)
- 项目设计基于Labview的转子动平衡测控系统源码+系统软件说明书.zip
- 课程设计Layabox+Unity制作的模型展示场景,鼠标、手指操控.zip