查询后GridView显示更新-ASP.NET

//GridView aspx页面后台cs代码
protected void btnQuery_Click(object sender, EventArgs e)
{
string adminID = this.tbxadminID.Text;
string adminName = this.tbxadminName.Text;
Administrator admin = new Administrator();
DataSet ds = admin.GetQuery(adminID,adminName);
this.GridView1.DataSourceID = null;
this.GridView1.DataSource = ds;
this.GridView1.PageIndex = 0;
this.GridView1.DataBind();
}


//后台App_code C#代码:
public DataSet GetQuery(string adminID, string adminName)
{
//方法外定义private string SELECT_INFO = "select admin_ID,admin_name,admin_sex,admin_position,admin_tel,admin_office from Administrator where 1 = 1";
if (adminID != "")
{
SELECT_INFO += "and admin_ID like '%" + int.Parse(adminID) + "%'";
}
if (adminName != "")
{
SELECT_INFO += "and admin_name like '%" + adminName + "%'";
}

            string sqlConnectionStr = "Server = .; DataBase = Experiment; User ID = sa; Password = 585858";
            SqlConnection sqlConnection = new SqlConnection(sqlConnectionStr);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand(SELECT_INFO, sqlConnection);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataSet ds = new DataSet();
            sqlDataAdapter.Fill(ds);
            DataTable administrator = ds.Tables[0];
            sqlConnection.Close();

            return ds;
        }
    }

初始时GridView显示数据库Experiment中表administrator的信息(密码不显示),然后我设置了两个textBox分别为工号和姓名和一个查询按钮,我想输入工号和姓名,点击查询,GridView显示的内容变为查询后的信息,但是以上两个方法为何实现不了,输入点击查询后还是原来表中的所有信息。

查看全部
Junegreat
Junegreat
2017/04/17 04:35
  • asp.net
  • 数据库
  • gridview
  • 点赞
  • 收藏
  • 回答
    私信

1个回复