objectdatasource问题??

snowfox_1985 2008-10-22 10:42:04
前台页面如下:

<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里输入查询条件然后查询,只需点击一次按钮就可以查得到数据,为什么会这样??
...全文
161 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧