objectdatasource问题??
前台页面如下:
<div>
关键字
<asp:TextBox ID="txtKey" runat="server"> </asp:TextBox>
<font color="red">按文号或标题模糊查询 </font>
<asp:Button ID="btnFind" runat="server" Text="查 询" onclick="btnFind_Click" /> </div>
<asp:GridView ID="grvFilelist" runat="server" AutoGenerateColumns="False" AllowPaging="true"
DataSourceID="ObjectDataSource1" onrowcommand="grvFilelist_RowCommand" DataKeyNames="id"
Width="95%" ondatabound="grvFilelist_DataBound" PagerSettings-Visible="false">
<Columns>
<asp:BoundField DataField="priority" HeaderText="紧急程度" />
<asp:BoundField DataField="file_type" HeaderText="类型" />
<asp:BoundField DataField="file_no" HeaderText="文号" />
<asp:BoundField DataField="title" HeaderText="标题" />
<asp:BoundField DataField="valid_time" HeaderText="有效期" />
<asp:BoundField DataField="write_man" HeaderText="编制人" />
<asp:BoundField DataField="write_time" HeaderText="编制日期" />
<asp:BoundField DataField="check_man" HeaderText="审核人" />
<asp:TemplateField HeaderText="审核时间">
<ItemTemplate>
<%# FormatNullDateTime(Eval("check_time").ToString()) %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="send_man" HeaderText="发送人" />
<asp:TemplateField HeaderText="发送时间">
<ItemTemplate>
<%# FormatNullDateTime(Eval("send_time").ToString()) %>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Image" CommandName="Count"
ImageUrl="~/images/A168.GIF" Text="统计" HeaderText="统计" />
<asp:ButtonField ButtonType="Image" CommandName="Read"
ImageUrl="~/images/A083.GIF" Text="查看" HeaderText="查看" />
</Columns>
<EmptyDataTemplate>
<h5>没有文件 </h5>
</EmptyDataTemplate>
</asp:GridView>
<uc:GridViewPager id="gvp" runat="server"> </uc:GridViewPager>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetRecordsByLimit" TypeName="SwInfoSys.Bo.Notices"
onselecting="ObjectDataSource1_Selecting" EnablePaging="true" SelectCountMethod="GetRecordsCount">
<SelectParameters>
<asp:Parameter Name="condition" Type="String" />
<asp:Parameter Name="args" Type="Object" />
<asp:Parameter Name="order" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
后台代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
}
gvp.SetDataGrid = grvFilelist;
}
protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
string condition = "com_id = ?";
if (txtKey.Text.CompareTo("") != 0)
{
condition += " and file_no like ? or title like ?";
string like = "%" + txtKey.Text + "%";
e.InputParameters["args"] = new object[] { this.FComID, like, like };
}
else
{
e.InputParameters["args"] = new object[] { this.FComID };
}
e.InputParameters["condition"] = condition;
e.InputParameters["order"] = "write_time desc";
}
protected void btnFind_Click(object sender, EventArgs e)
{
grvFilelist.DataBind();
}
protected void grvFilelist_DataBound(object sender, EventArgs e)
{
gvp.ShowPager();
}
gvp是我的一个用户分页控件
问题是:第一次进入这个页面时,在分页控件里翻到下一页(或者随便翻到哪一页),然后在txtKey里输入查询条件,第一次点击按钮时总是查不到数据,要再点击一次才能查到数据,如果在第一次进入这个页面后直接在txtKey里输入查询条件然后查询,只需点击一次按钮就可以查得到数据,为什么会这样??