日期:2014-05-18 浏览次数:20468 次
<asp:datagrid id="DGPatent" runat="server" Width="1123px" Height="40px" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Vertical" ForeColor="Black" PageSize="20"> <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#CE5D5A"></SelectedItemStyle> <AlternatingItemStyle BackColor="White"></AlternatingItemStyle> <ItemStyle BackColor="#F7F7DE"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#6B696B"></HeaderStyle> <FooterStyle BackColor="#CCCC99"></FooterStyle> <Columns> <asp:BoundColumn DataField="pid" SortExpression="pid" HeaderText="专利序号"></asp:BoundColumn> <asp:BoundColumn DataField="pno" HeaderText="专利号"></asp:BoundColumn> <asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="pid" DataNavigateUrlFormatString="searchcontent.aspx?pid={0}" DataTextField="pname" HeaderText="专利名称"></asp:HyperLinkColumn> <asp:BoundColumn DataField="type" SortExpression="type" HeaderText="专利类别"></asp:BoundColumn> <asp:BoundColumn DataField="state" SortExpression="state" HeaderText="专利状态"></asp:BoundColumn> <asp:BoundColumn DataField="oprginator" HeaderText="发明人或参加人"></asp:BoundColumn> <asp:BoundColumn DataField="pdate" SortExpression="pdate" HeaderText="申请日期"></asp:BoundColumn> <asp:BoundColumn DataField="adate" HeaderText="授权日期"></asp:BoundColumn> <asp:BoundColumn DataField="abdate" HeaderText="废止日期"></asp:BoundColumn> <asp:BoundColumn DataField="ptime" HeaderText="保护期限"></asp:BoundColumn> <asp:BoundColumn DataField="proposer" HeaderText="专利申请人"></asp:BoundColumn> <asp:BoundColumn DataField="country" HeaderText="专利国别"></asp:BoundColumn> <asp:BoundColumn DataField="unit" HeaderText="授权单位"></asp:BoundColumn> <asp:BoundColumn DataField="remark" HeaderText="备注"></asp:BoundColumn> </Columns> <PagerStyle NextPageText="上一页" PrevPageText="下一页" HorizontalAlign="Center" ForeColor="Black" BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle> </asp:datagrid>
private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!IsPostBack) { ViewState["Direction"] = "ASC"; BindGrid(string.Empty); } //这两行代码有问题.因为这个所以把你的排序冲没了..这两行代码每次postback都会执行的.这样的话.你BindGrid()方法就没用了 DGPatent.DataSource=ClsDB.ExecuteQueryToDataSet("select * from patentInfo"); DGPatent.DataBind(); }
------解决方案--------------------
你这个排序的确有问题,你没有保存查询条件,当点击查询的时候把this.txtpno.Text 的值保存下来,排序的那个函数里要加上这个搜索的条件的,不然一排序结果就变了.帮你大概的修改了一下,具体细节还要你自己完善.