日期:2014-05-17  浏览次数:20433 次

一个GridView怎么再次绑定呀
就是我第一次绑定如下
C# code
protected void GridViewBind(string condition)
        {
            string sql = "select *from teacher";
            Common comn = new Common();
            DataSet ds = comn.GetDataSet(sql);
            #region 实现单击列标题排序要用到的代码
            DataView myView = ds.Tables[0].DefaultView;
            string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
            myView.Sort = sort;
            #endregion
            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
            
        }
 
我还想用这个GridView来做查询的显示,我看别人改变函数里面的参数condition来实现,具体就不知道了!第二段代码怎么绑定
C# code
protected void BtnConfirm1_Click(object sender, EventArgs e)
        {
            string sql = "select   * from  teacher  where 1=0 ";
            string sqlCondition = string.Empty;
            if (txtTeacherNum.Text.Trim() != "") 
            {
                sqlCondition += "and   tid   like   '" + txtTeacherNum.Text.Trim() + "%'   "; 
            }
            if (txtTeacherName.Text.Trim() != "") 
            {
                sqlCondition += "and   tname   =   '%" + txtTeacherName.Text.ToString() + "%'   "; 
            }
            if (txtSubject.Text.Trim() != "") 
            {
                sqlCondition += "and  subject   =   '%" + txtSubject.Text.ToString() + "%'   "; 
            }
            sql += sqlCondition;
            Common comm = new Common();
            comm.ExecuteNonQuery(sql);
            GridView1.EditIndex = -1;
                // 这里怎么绑定呀?

            
        }


------解决方案--------------------
调用GridViewBind啊

GridViewBind("")