⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 way_list.aspx.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 CS
字号:
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 Manage_Way_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.bind();
        }
    }
    public void bind()
    {
        SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
        strcon.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select 编号,线路,发布类型,价格,公司名称,发布日期,发布用户 from tb_Way order by 编号 desc", strcon);
        DataSet ds = new DataSet();
        sda.Fill(ds,"tb_Way");
        this.GridView1.DataSource=ds.Tables["tb_Way"];
        this.GridView1.DataKeyNames = new string[] {"编号"};
        this.GridView1.DataBind();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {

    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        string strsql = "";
        if (TextBox1.Text.Trim() == "")
        {
            strsql = "select * from tb_Way";
        }
        else
        {
            strsql = "select * from tb_Way where 线路 like '%" + TextBox1.Text.Trim() + "%'";
        }
        SqlConnection conn = new SqlConnection("server=.;database=db_04;uid=sa;pwd=");
        SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
        DataSet ds = new DataSet();
        sda.Fill(ds, "news");
        GridView1.DataSource = ds.Tables["news"].DefaultView;
        GridView1.DataKeyNames = new string[] { "编号" };
        GridView1.DataBind();
        Button2.Enabled = true;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
        CheckBoxList1.DataSource = getname();
        CheckBoxList1.DataTextField = "name";
        CheckBoxList1.DataBind();
        for (int i = 0; i < CheckBoxList1.Items.Count; i++)
        {
            if (CheckBoxList1.Items[i].Text == "编号")
            {
                CheckBoxList1.Items[i].Selected = true;
                CheckBoxList1.Items[i].Enabled = false;
            }
        }
    }
    private SqlDataReader getname()//检索字段名
    {
        string a = "select name from syscolumns where id=object_id('tb_Way')";
        string cmdtxt1 = "Server=(local);DataBase=db_04;Uid=sa;Pwd=";
        SqlConnection Con = new SqlConnection(cmdtxt1);
        Con.Open();
        SqlCommand mycommand1 = new SqlCommand(a, Con);
        SqlDataReader dr2 = mycommand1.ExecuteReader();
        return dr2;
    }
    protected void Button3_Click1(object sender, EventArgs e)
    {
        if (CheckBoxList1.SelectedValue.Length == 0)
        {
            Page.RegisterStartupScript("", "<script>alert('请选择要显示的列名')</script>");
        }
        else
        {
            SqlConnection conn = new SqlConnection("server=.;database=db_04;uid=sa;pwd=");
            string str = "";
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    str += CheckBoxList1.Items[i].Text + ",";
                }
                if (CheckBoxList1.Items[i].Text == "编号")
                {
                    CheckBoxList1.Items[i].Selected = true;
                    CheckBoxList1.Items[i].Enabled = false;
                }
            }
            string y = str.Substring(0, str.Length - 1);
            string x = "select " + y + " " + "from tb_Way where 线路 like '%" + TextBox1.Text.Trim() + "%'";
            SqlDataAdapter sda = new SqlDataAdapter(x, conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "news");
            GridView1.DataSource = ds.Tables["news"].DefaultView;
            GridView1.DataBind();
        }
    }
}

⌨️ 快捷键说明

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