newsmanage.aspx.cs

来自「microsoft公司在进行ASP.NET 2.0培训课时课堂操作演示代码。」· CS 代码 · 共 53 行

CS
53
字号
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;
using System.Data.SqlClient;
public partial class Admins_NewsManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            this.GetCategoryDataBind();
            this.GetNewsInfoDataBind();
        }
    }

    private void GetNewsInfoDataBind()
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["NewsDBConnectionString"].ConnectionString;
        SqlConnection Con = new SqlConnection(constr);
        string Sql = "select * from NewsInfo Where CategoryId='" + this.DropDownList1.SelectedValue+"'";
        SqlDataAdapter Sda = new SqlDataAdapter(Sql,Con);
        DataSet Ds = new DataSet();
        Sda.Fill(Ds, "NewsInfo");
        this.GridView1.DataSource = Ds.Tables[0].DefaultView;
        this.GridView1.DataBind();
    }
    private void GetCategoryDataBind()
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["NewsDBConnectionString"].ConnectionString;
        SqlConnection Con = new SqlConnection(constr);
        string Sql = "select * from Categories";
        SqlDataAdapter Sda = new SqlDataAdapter(Sql, Con);
        DataSet Ds = new DataSet();
        Sda.Fill(Ds, "Categories");
        this.DropDownList1.DataSource = Ds.Tables[0].DefaultView;
        this.DropDownList1.DataTextField = "CategoryName";
        this.DropDownList1.DataValueField = "categoryId";
        this.DropDownList1.DataBind();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.GetNewsInfoDataBind();
    }
}

⌨️ 快捷键说明

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