show.aspx<div style="width:100%;margin:10px auto;">
        <div style="background-image:url(image/date_bg.gif);width:100%;height:41px;padding-top:8px;border:1px solid #eee;">
            <asp:Button ID="ButtYesterDay" runat="server" Text="昨天" width="77px" 
                CssClass="but" onclick="ButtYesterDay_Click"/>
            <asp:Button ID="ButtNearSenvenDay" runat="server" Text="最近7天" width="77px" 
                CssClass="but" onclick="ButtNearSenvenDay_Click"/>
            <asp:Button ID="ButtNearThirtyDay" runat="server" Text="最近30天" width="77px" 
                CssClass="but" onclick="ButtNearThirtyDay_Click"/>
            <asp:Button ID="ButtLastMonth" runat="server" Text="上一个月" width="77px" 
                CssClass="but" onclick="ButtLastMonth_Click"/>
            从:<asp:TextBox ID="TextBStartTime" runat="server" CssClass="but" Width="100px" onfocus="setday(this);"></asp:TextBox>
            至:<asp:TextBox ID="TextBEndTime" runat="server" CssClass="but" Width="100px" onfocus="setday(this);"></asp:TextBox>
            请输入商品名称或ID<asp:TextBox ID="TextBSearch" runat="server" CssClass="but" Width="100px"></asp:TextBox>
            <asp:Button ID="ButtQuery" runat="server" Text="查询" width="77px" CssClass="but" 
                onclick="ButtQuery_Click" />
<asp:GridView ID="GridViewBySearch" runat="server" Width="100%" 
            AutoGenerateColumns="False" CellPadding="0" ForeColor="#333333" 
            GridLines="None">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="缩略图">
                <ItemTemplate>
                    <asp:Image ID="ImageProductUrl" runat="server" Width="80px" Height="80px" ImageUrl='<%# Eval("PicUrl")%>' />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="产品地址">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                      <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("CurrentPage")%>' Target="_blank"><%# Eval("ItemUrl")%></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="预览">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                     <a href="javascript:window.location.href='TwoProduct.aspx?ID='+escape('<%# Eval("CurrentPage") %>')" title="查看商品模版" target="_blank"><asp:Label ID="LabCurrentPage" runat="server" Text='<%# Eval("CurrentPage").ToString().Length > 50 ? Eval("CurrentPage").ToString().Substring(0, 50) + "..." : Eval("CurrentPage")%>'></asp:Label></a>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="更新">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                    <asp:Button ID="ButtonUpdate" runat="server" CommandArgument='<%#Eval("CurrentPage") %>' Text="更新" Width="77px" ToolTip="将信息更新到商品描述中" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="价格">
                <ItemTemplate>
                    <asp:Label ID="LabelMoney" runat="server" Text='<%# Eval("ProcMoney")%>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="点击次数">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                    <asp:Label ID="LabelCount" runat="server" Text='<%# Eval("coun")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server" ForeColor="White" OnClick="ButtonAutoSearch" CommandName="Page" CommandArgument="First" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex>0 %>">首页</asp:LinkButton>
            <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Page" ForeColor="White" CommandArgument="Prev" OnClick="ButtonAutoSearch" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex>0 %>">上一页</asp:LinkButton>
            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Page" ForeColor="White" CommandArgument="Next" OnClick="ButtonAutoSearch" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex<((GridView)Container.Parent.Parent).PageCount-1 %>">下一页</asp:LinkButton>
            <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Page" ForeColor="White" CommandArgument="Last" OnClick="ButtonAutoSearch" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex<((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
            &nbsp;<span style="font-family: Georgia;">第<asp:Label ID="Label2" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1 %>'></asp:Label>页/共
            <asp:Label ID="Label3" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页&nbsp;每页
            <asp:Label ID="Label4" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageSize%>'></asp:Label>条记录</span>             
        </PagerTemplate>
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>    
        </div>

解决方案 »

  1.   

    show.aspx.cs protected void ButtQuery_Click(object sender, EventArgs e)//搜索
            {
                strtime = TextBStartTime.Text;
                endtime = TextBEndTime.Text;
                serth = TextBSearch.Text;
                GridViewByYestoday.Visible = false;
                GridViewByThreeDay.Visible = false;
                GridViewByServenDay.Visible = false;
                GridViewBySearch.Visible = true;
                GridViewByLastMonth.Visible = false;
                if (TextBStartTime.Text != "" && TextBEndTime.Text != "")
                {
                    string stOK = IsDate(TextBStartTime.Text);
                    string strNo = IsDate(TextBEndTime.Text);
                    if (stOK == "OK" && strNo == "OK")
                    {
                        if (DateTime.Parse(TextBEndTime.Text) > DateTime.Parse(TextBStartTime.Text))
                        {
                            if (TextBSearch.Text == "")
                            {
                                bindByYesToday(TextBSearch.Text,TextBEndTime.Text,GridViewBySearch);
                            }
                            else
                            {
                                string strSearch = TextBSearch.Text;
                                if (CheckCharIsNumber(strSearch))
                                {
                                    SearchID(TextBStartTime.Text, TextBEndTime.Text, strSearch);
                                }
                                else
                                {
                                    SearchName(TextBStartTime.Text, TextBEndTime.Text, strSearch);
                                }
                            }
                        }
                        else
                        {
                            ClassData.WebMessageBox(Page, "您的结束日期比起始日期小,请更正后再次输入!", "");
                        }
                    }
                    else
                    {
                        ClassData.WebMessageBox(Page, "请正确输入日期格式!", "");
                    }
                }
                else
                {
                    ClassData.WebMessageBox(Page, "请输入您要选择的日期区间", "");
                }
            }
            public static string IsDate(string StrSource)
            {
                DateTime dt;
                if (DateTime.TryParse(StrSource, out dt))
                {
                    return "OK";
                }
                else
                {
                    return "NO";
                }
            }
            private void SearchID(string strTime, string endTime, string strID)
            {
                string sqlStr = "select CurrentPage,PicUrl,ItemUrl,ProcMoney,count(*) as coun from pro where ItemUrl != '' and CreateDate between '" + strTime + " 00:00:00' and '" + endTime + " 23:59:59' and CurrentPage like '%" + strID + "%' group by CurrentPage,ItemUrl,PicUrl,ProcMoney,ItemUrl order by coun desc";
                SqlConnection myConn = new SqlConnection("server=sa;database=show;uid=sa;pwd=sa;");
                SqlDataAdapter myAdapter = new SqlDataAdapter(sqlStr, myConn);
                DataSet ds = new DataSet();
                myAdapter.Fill(ds, "authors");
                GridViewBySearch.DataSource = ds.Tables["authors"];
                GridViewBySearch.AllowPaging = true;//设置他可以分页,前台必须设置分页模板不可见,否则他要使坏 
                GridViewBySearch.PageSize = 10;//分页大小为10 
                GridViewBySearch.DataBind();
            }
            private void SearchName(string strTime, string endTime, string strName)//根据搜索条件找出符合条件的数据绑定到gridview
            {
                string sqlStr = "select CurrentPage,PicUrl,ItemUrl,ProcMoney,count(*) as coun from pro where ItemUrl like '%" + strName + "%'  ItemUrl != '' and CreateDate between '" + strTime + " 00:00:00' and '" + endTime + " 23:59:59' group by CurrentPage,PicUrl,ProcMoney,ItemUrl order by coun desc";
                SqlConnection myConn = new SqlConnection("server=sa;database=show;uid=sa;pwd=sa;");
                SqlDataAdapter myAdapter = new SqlDataAdapter(sqlStr, myConn);
                DataSet ds = new DataSet();
                myAdapter.Fill(ds, "authors");
                GridViewBySearch.DataSource = ds.Tables["authors"];
                GridViewBySearch.AllowPaging = true;//设置他可以分页,前台必须设置分页模板不可见,否则他要使坏 
                GridViewBySearch.PageSize = 10;//分页大小为10 
                GridViewBySearch.DataBind();
            }
            public bool CheckCharIsNumber(string strtempstr)
            {
                bool returntempbool = true;
                for (int i = 0; i < strtempstr.Length; i++)
                {
                    if (!Char.IsNumber(strtempstr, i))
                    {
                        returntempbool = false;
                    }
                }
                return returntempbool;
            }
    protected void ButtonAutoSearch(object sender, EventArgs e)//分页
            {
                    switch (((LinkButton)sender).CommandArgument.ToString())
                    {
                        case "First":
                            GridViewByLastMonth.PageIndex = 0;
                            break;
                        case "Last":
                            GridViewByLastMonth.PageIndex = GridViewByLastMonth.PageCount - 1;
                            break;
                        case "Prev":
                            GridViewByLastMonth.PageIndex = GridViewByLastMonth.PageIndex - 1;
                            break;
                        case "Next":
                            GridViewByLastMonth.PageIndex = GridViewByLastMonth.PageIndex + 1;
                            break;
                    }
    //需要绑定数据函数,可以该调用那个?绑定SearchName()还是SearchID();应该价格判断,
                }
      

  2.   

    你的方法都已经写好了,简单的查数据分页而已。我不明白LZ到底要做什么?是不是想把SearchID()方法跟SearcheName()这两方法里面的参数中的前两个改成价格?用价格作为条件去查询数据 分页?
      

  3.   

    当我调用ButtonAutoSearch分页时候,需要绑定数据~
    因为我是根据搜索条件来执行查询的~所以我不知道到底是绑定SearchID()还是绑定SearcheName()~