list.aspx.cs

来自「这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代」· CS 代码 · 共 71 行

CS
71
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 manage_list : System.Web.UI.Page
{
    BaseClass bc = new BaseClass();
    static string strStyle;
    static int pagecount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
            int n = Convert.ToInt16(Request.QueryString["id"]);
            switch (n)
            {
                case 1: strStyle = "style='时政要闻'";
                    break;
                case 2: strStyle = "style='经济动向'";
                    break;
                case 3: strStyle = "style='世界军事'";
                    break;
                case 4: strStyle = "style='科学教育'";
                    break;
                case 5: strStyle = "style='法治道德'";
                    break;
                case 6: strStyle = "style='社会现象'";
                    break;
                case 7: strStyle = "style='体育世界'";
                    break;
                case 8: strStyle = "style='时尚娱乐'";
                    break;
                default: strStyle = "style like '%%'";
                    break;
            }
            GridView1.DataSource = bc.GetDataSet("select * from tbNews where " + strStyle + "order by id", "tbNews");
            GridView1.DataKeyNames = new string[] { "id" };
            GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        bc.ExecSQL("delete  from tbNews where id='" + this.GridView1.DataKeys[e.RowIndex].Value.ToString() + "'");
        GridView1.DataSource = bc.GetDataSet("select * from tbNews where " + strStyle, "tbNews");
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void cmdSearch_Click(object sender, EventArgs e)
    {
        string strSql = "select * from tbnews where style='" + DropDownList1.Text + "' and content like '%" + TextBox1.Text + "%'";
        GridView1.DataSource = bc.GetDataSet(strSql, "tbNews");
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[3].Text =Convert.ToDateTime(e.Row.Cells[3].Text).ToShortDateString();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?