Beispiel #1
0
    public void LeaveWordfillgv()            //用户自定义的方法
    {
        string        SqlStr = "select * from tb_LeaveWord order by lTime desc";
        SqlConnection con    = new SqlConnection(EP.GetConStr());

        con.Open();                         //打开数据库连接
        SqlDataAdapter sda = new SqlDataAdapter(SqlStr, con);
        DataSet        ds  = new DataSet(); //声明一个DataSet的对象,并将该对象ds实例化

        sda.Fill(ds, "tb_LeaveWord");       //将tb_LeaveWord填充到数据库中
        this.GvLeaveWord.DataSource = ds;
        this.GvLeaveWord.DataBind();        //将数据绑定到GridView控件中
        for (int i = 0; i <= this.GvLeaveWord.Rows.Count - 1; i++)
        {
            DataRowView mydrv;  //声明一个DataRowView的对象
            string      gintro;

            if (this.GvLeaveWord.PageIndex == 0)
            {
                EP.GetConStr();

                mydrv  = ds.Tables["tb_LeaveWord"].DefaultView[i];
                gintro = Convert.ToString(mydrv["Title"]);
                this.GvLeaveWord.Rows[i].Cells[1].Text = ep.SubStr(gintro, 10);
            }
        }
        con.Close();
    }
    public void GongGaofillgv()            //用户自定义的方法
    {
        string        SqlStr = "select * from tb_GongGao order by GTime desc";
        SqlConnection con    = new SqlConnection(EP.GetConStr());

        con.Open();                         //打开数据库连接
        SqlDataAdapter sda = new SqlDataAdapter(SqlStr, con);
        DataSet        ds  = new DataSet(); //声明一个DataSet的对象,并将该对象ds实例化

        sda.Fill(ds, "tb_GongGao");         //将tb_GongGao填充到数据库中
        this.GvGongGao.DataSource = ds;
        this.GvGongGao.DataBind();          //将数据绑定到GridView控件中
        for (int i = 0; i <= this.GvGongGao.Rows.Count - 1; i++)
        {
            DataRowView mydrv;  //声明一个DataRowView的对象
            string      gintro; //声明一个字符串变量
            if (this.GvGongGao.PageIndex == 0)
            {
                EP.GetConStr();//调用EP类中的GetConStr()方法
                mydrv  = ds.Tables["tb_GongGao"].DefaultView[i];
                gintro = Convert.ToString(mydrv["content"]);
                this.GvGongGao.Rows[i].Cells[1].Text = ep.SubStr(gintro, 10);
            }
        }
        con.Close();//关闭数据库链接
    }