利用修改AccessDataSource的sql语句来检索数据

Proj_Edit.aspx


--------------------------------------------------------------------------------

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                AllowSorting="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
                CellPadding="5" DataKeyNames="货号" DataSourceID="AccessDataSource1"
                ForeColor="#333333" GridLines="None" PageSize="18" Width="715px"
                style="text-align: left">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:BoundField DataField="货号" HeaderText="货号" SortExpression="货号"
                        InsertVisible="False" ReadOnly="True" />
                    <asp:BoundField DataField="名称" HeaderText="名称" SortExpression="名称" />
                    <asp:BoundField DataField="图片" HeaderText="图片" SortExpression="图片" />
                    <asp:BoundField DataField="主页地址" HeaderText="主页地址" SortExpression="主页地址" />
                    <asp:BoundField DataField="所属分类" HeaderText="所属分类" SortExpression="所属分类" />
                    <asp:BoundField DataField="排名竞价" HeaderText="排名竞价" SortExpression="排名竞价" />
                </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
            </asp:GridView>

               <asp:AccessDataSource ID="AccessDataSource1" runat="server"
                    DataFile="~/App_Data/Proj.mdb"
                    SelectCommand="SELECT * FROM [Proj] ORDER BY [货号] DESC">
                </asp:AccessDataSource>

Proj_Edit.aspx.cs


--------------------------------------------------------------------------------

protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "SELECT * FROM Proj  WHERE 名称 like '%" + TextBox1.Text.Trim() + "%' ORDER BY 排名竞价 DESC";
            AccessDataSource1.SelectCommand = sql;
            GridView1.DataBind();
        }

posted @ 2010-09-18 09:44  Yao,Mane  阅读(546)  评论(0编辑  收藏  举报