这是ASPX的代码:
<asp:Label ID="Label2" runat="server" ForeColor="#00C000" Text="可以进行条件选择: " Width="174px"></asp:Label>&nbsp;
            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
                DataTextField="name" DataValueField="name" Width="137px">
            </asp:DropDownList>&nbsp;
            <asp:Label ID="Label1" runat="server" ForeColor="#00C000" Text="LIKE" Width="83px"></asp:Label>
            &nbsp;&nbsp;
            <asp:TextBox ID="TextBox1" runat="server" Width="177px"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Size="Medium" Font-Strikeout="False"
                Font-Underline="False" OnClick="Button1_Click" Text="确 认" Width="110px" />
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:qsbConnectionString %>"
            SelectCommand="select name from syscolumns where id in (select id from sysobjects where name='v_sjsfw')">
        </asp:SqlDataSource><DIV align="center"><FONT face="幼圆" size="4">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" PageSize="100" ShowFooter="True">
            <Columns>
                <asp:BoundField DataField="fwfsrq" HeaderText="fwfsrq" ReadOnly="True" SortExpression="fwfsrq" />
                <asp:BoundField DataField="fwsjlb" HeaderText="fwsjlb" SortExpression="fwsjlb" />
                <asp:BoundField DataField="fwmxzh" HeaderText="fwmxzh" ReadOnly="True" SortExpression="fwmxzh" />
                <asp:BoundField DataField="FWXWDM" HeaderText="FWXWDM" SortExpression="FWXWDM" />
                <asp:BoundField DataField="FWZQDM" HeaderText="FWZQDM" SortExpression="FWZQDM" />
                <asp:BoundField DataField="fwgddm" HeaderText="fwgddm" ReadOnly="True" SortExpression="fwgddm" />
                <asp:BoundField DataField="FWMRJE" HeaderText="FWMRJE" SortExpression="FWMRJE" />
                <asp:BoundField DataField="FWMCJE" HeaderText="FWMCJE" SortExpression="FWMCJE" />
                <asp:BoundField DataField="FWZJYE" HeaderText="FWZJYE" SortExpression="FWZJYE" />
                <asp:BoundField DataField="FWZYSM" HeaderText="FWZYSM" SortExpression="FWZYSM" />
                <asp:BoundField DataField="fwsjsm" HeaderText="fwsjsm" ReadOnly="True" SortExpression="fwsjsm" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:qsbConnectionString %>"
            SelectCommand="SELECT * FROM [v_sjsfw] ORDER BY [fwfsrq] DESC"></asp:SqlDataSource>
      </FONT></DIV>.cs中的相应代码:protected void Page_Load(object sender, System.EventArgs e)
{
            if (!IsPostBack)
            {              
            }
}
        protected void Button1_Click(object sender, EventArgs e)
        {
            //string mcomm = "select * from v_sjsqs where " + this.DropDownList1.SelectedValue.ToString() + " like '%" + this.TextBox1.Text.ToString().Trim() + "%'";
            //Response.Write(mcomm);
            if (this.TextBox1.Text.ToString().Trim().Length > 0)
            {
                this.SqlDataSource1.SelectCommand = "select * from v_sjsfw where " + this.DropDownList1.SelectedValue.ToString() + " like '%" + this.TextBox1.Text.ToString().Trim() + "%' order by fwfsrq desc";
                this.SqlDataSource1.DataBind();
                this.GridView1.DataBind();
            }
            else
            {
                this.SqlDataSource1.SelectCommand = "select * from v_sjsfw order by fwfsrq desc";
                this.SqlDataSource1.DataBind();
                this.GridView1.DataBind();
            }
        }

解决方案 »

  1.   


    你翻页后,又重新postback了
    数据肯定刷新了。
    你可以把条件保存在cookie里面,page_load的时候进行加载
      

  2.   

    我估计是你设置过滤条件后,翻页后,条件没有了,数据全部显示了!如果是这样,你可用STATIC 定义静态变量把条件保存起来翻页的时候使用这个静态变量填充数据
      

  3.   

    在Page_Load中加上:
    if (IsPostBack && ViewState["SelectCommand"]!=null)
    {  
      SqlDataSource1.SelectCommand = ViewState["SelectCommand"] as string;
    }在 Button1_Click方法的最后加上:
    ViewState["SelectCommand"] = SqlDataSource1.SelectCommand;
      

  4.   

    简单地照抄Scott Mitchell的asp.net2.0入门教程都不会了?http://blog.csdn.net/Freeze_Soul/archive/2007/09/11/1779987.aspx如果这类问题还搞不定,不如先做完这个教程上所有例子,然后再开始编程工作。
      

  5.   

    例子很好,刚学习了一下.
    不过有一个疑惑,一般资料都显示,在有数据源控件的页面中,页面生命周期大致是这样的:
    1. page init
    2. page.load
    3. 处理控件事件
    4. 数据源控件更新操作.
    5. page.preRender,此时执行数据源查询操作也就是说,数据源控件是在page.preRender阶段查询数据,远在page.load之后.
    但这个教程中,却在page.load代码中处理一系列 数据源控件的相关处理,摘:protected void Page_Load(object sender, EventArgs e)
    {
        // Get the data from the SqlDataSource as a DataView
        DataView randomCategoryView =
            (DataView)RandomCategoryDataSource.Select(DataSourceSelectArguments.Empty);
        if (randomCategoryView.Count > 0)
        {
            // Assign the CategoryName value to the Label
            CategoryNameLabel.Text =
                string.Format("Here are Products in the {0} Category...",
                    randomCategoryView[0]["CategoryName"].ToString());
        }
    }这代码难道不是表明,RandomCategoryDataSource数据源控件在page.load事件中就已查询出了数据?