vs2005中  gridview是在前台数据绑定的,在后台的查询按钮事件中,怎么写代码?我用之前的VS2003中的代码显示的提示是数据源冲突,请高手指点~多谢
        string sort = Request.Form["bigclass"];
        string pname = Request.Form["pname"];        string he = "Select *,(innum-salenum-retnum) as intnum  from inventorys where 1=1";
        if (sort != "")
        {
            he += "and bigcla='" + sort + "'";
        }
        if (pname != "")
        {
            he += "and pname='" + pname + "'";
        }
      string strcon = ConfigurationManager.ConnectionStrings["mConnectionString"].ConnectionString;
        
        SqlConnection objcon = new SqlConnection(strcon);
        objcon.Open();
        DataSet ds = new DataSet();
        try
        {
            SqlDataAdapter adapter = new SqlDataAdapter(he, objcon);
            adapter.Fill(ds, "inventorys");
            GridView1.DataSource = ds.Tables["inventorys"].DefaultView;
            GridView1.DataBind();            int startIndexs;
            startIndexs = ds.Tables[0].DefaultView.Count;            objcon.Close();// 
        }
        catch
        {
            Response.Write("<script language='javascript'> alert('因您网络速度过慢,请稍后再试!');</script>");
        }

解决方案 »

  1.   

    思路不都一样吗?获取文本值,拼接sql语句,到数据库模糊查询
      

  2.   

    页面肯定有个Button 吧,加上点击事件
    <asp:TextBox id="pname" runat="server" />
    <asp:Button .... OnClick="btnSearch_Click" />
    protected void btnSearch_Click(object:sender,EventArg:string)
    {
    string sort = 页面控件的值
      string pname = pname.Text;
    后面代码一样了
    }
      

  3.   

     Rock870210
    兄弟,你说的这个我知道,我问的是前台手工配好的GRIDVIEW,在后台怎么写用文本框里的值来写查询语句数据源的代码
      

  4.   

    前台页面已经写了数据源
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mConnectionString %>"
                SelectCommand="Select *,(innum-salenum-retnum) as intnum  from inventorys where 1=1">
            </asp:SqlDataSource>后台在查询按钮中,这个数据源该如何写?
      

  5.   

    看看SqlDataSource1的属性有没有可以更改sql语句。你的控件跟数据源是绑定的,前台每次加载都会重新查询这个数据源。所以后台再次绑定会出现冲突,建议lz都使用后台,分页查询可以自己写,锻炼一下。
    个人观点,我也是菜鸟
      

  6.   

    是获取 这个文本框的值,然后更具这个值来拼sql语句是吗??