我设置了一个GridView.给他绑定了一个表. 
又设置了4个TextBox.一个BUTTON 
我想实现这样的效果:填一个TextBox,点BUTTON,GridView就显示出和TextBox内容相关的一行数据. 
比如,表里有姓名,学好,成绩,性别4项.TextBox1里填写男,GridView就显示出所有男生的相关信息.再在TextBox2里填写李拓,GridView里就显示出所有叫李拓的男生的相关信息.

解决方案 »

  1.   

    写一个组合查询。如果按你说的效果需要用到AJAX,你可以根据自己的需要设置
      

  2.   

    直接在你的BUTTON单击事件进行对输入条件的判断,再组织SQL语句再邦定。string MyCondictions = null;        //定义SQL语句条件变量
    string MySQL = "select * from 表"
            //判断文本框是否为空,并对MyCondictions赋值
            if (!string.IsNullOrEmpty(TextBox.Text)) MyCondictions = " Sex='" + TextBox.Text + "'";        if (!string.IsNullOrEmpty(TextBox1.Text))
            {
                if (!string.IsNullOrEmpty(MyCondictions)) MyCondictions += " And ";
                MyCondictions += " Name='" + TextBox1.Text + "'";
            }        if (!string.IsNullOrEmpty(MyCondictions)) MySQL = MySQL + " Where" + MyCondictions;        //下面就再邦定GRID
      

  3.   

    把条件组合以下再去捞取数据,再绑定到GridView上就OK了
      

  4.   

     string where = "";
            if (TextBox1.Text.Trim() != "")
            {
                if (where== "")
                    where= "VLXR'" + TextBox1.Text + "'";
                else
                    where= " and " + TextBox1.Text + "'";        
            }
            if (TextBox2.Text.Trim() != "")
            {
                if (where== "")
                    where = "VJCR" + TextBox2.Text + "'";
                else
                    where= " and " + TextBox2.Text + "'";            
            }
            if (TextBox3.Text.Trim() != "")
            {
                if (where== "")
                    where = "VLXDH" + TextBox3.Text + "'";
                else
                    where= " and " + TextBox3.Text + "'";          
            }
            if (TextBox4.Text.Trim() != "")
            {
                if (where == "")
                    where= "CHYKH" + TextBox4.Text + "'";
                else
                    where= " and " + TextBox4.Text + "'";            
            }
            BB_HJZX_DDXX bll = new BB_HJZX_DDXX();
            DataSet ds = bll.GetList("where");
            GridView2.DataSource = ds;
            GridView2.DataBind();
    这样写可以吗?
      

  5.   

    还有个办法
    取下你要用到的DataSet以后
    实例化一个DataView,GridView绑定这个DataView
    每次都去替换DataView的FilterString就好了大概就是这样//取DataSet,假定为DS
    DataView dv1=new DataView(DS.Table[表名]);
    dv1.FilterString="";//这个是条件,比如name=textbox1.text
    GridView1.DataSource=dv1然后每次点击按钮的时候,把dv1的filterstring替换就好了。