如何在单独的页面上显示搜索结果 [英] How to display search results on a separate page

查看:96
本文介绍了如何在单独的页面上显示搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的search.aspx上,我使用网格视图显示搜索结果:

 <   asp:GridView     ID   =  GridView1    runat   =  server    DataSourceID   =  SqlDataSource1    AutoGenerateColumns   =  False   宽度  =  735px >  

< >
< asp:BoundField DataField = title HeaderText = title SortExpression = title > < / asp:BoundField >
< asp:BoundField DataField = fcontents HeaderText = fcontents SortExpression = fcontents > < / asp:BoundField >
< /列 >
< / asp:GridView >
< asp:SqlDataSource ID = SqlDataSource1 runat = server ConnectionString = <% $ ConnectionStrings:minusConnectionString%> SelectCommand = SELECT [title],[fcontents] FROM [tpost] WHERE([fcontents] LIKE'%'+ @ftetents +'%') >
< SelectParameters >
< < span class =code-leadattribute> asp:ControlParameter ControlID = TextBox1 名称 = fcontents PropertyName = 文字 < span class =code-attribute> 类型 = String / > ;
< / SelectParameters >
< / asp:SqlDataSource >
< asp:按钮 ID = Button1 runat = server 文本 = 按钮 / >
< asp:TextBox ID = TextBox1 runat = 服务器 > < / asp:TextBox >
< / div >



它工作正常,搜索结果显示在search.aspx页面中(我使用网格视图向导搜索结果)

并且在Master Page i中使用此代码;

 <   div     style   =  margin-removed 5px; float:left >  
< 表单 名称 = searchform 方法 < span class =code-keyword> = get class = searchform >
< 输入 类型 = hidden name = 执行 = 搜索 / >
< 输入 类型 = 隐藏 name = subaction value = search / >
< 输入 name = story id = story type = < span class =code-keyword> text / >
< 按钮 类型 = 提交 > 搜索< / button >
< / form >



现在,我希望当用户在母版页中搜索时,搜索结果会在新的search.aspx页面上打开。我可以做这项工作吗?谢谢

解决方案

< blockquote> ConnectionStrings:minusConnectionString%> SelectCommand = SELECT [title],[fcontents] FROM [tpost] WHERE([fcontents] LIKE'%'+ @fcontents +'%') >
< SelectParameters >
< asp :C ontrolParameter ControlID = TextBox1 名称 = fcontents PropertyName = 文字 类型 = 字符串 < span class =code-attribute> / >
< / SelectParameters >
< / asp:Sql DataSource >
< asp:按钮 ID = Button1 runat = server 文本 = 按钮 / >
< asp:TextBox ID = TextBox1 runat = server > < / asp:TextBox >
< / div >



它运行正常,搜索结果是显示在search.aspx页面中(我使用网格视图向导搜索结果)

在Master Page中我使用此代码;

 <   div    样式  =  margin-removed 5px; float:left >  
< 表单 名称 = searchform 方法 < span class =code-keyword> = get class = searchform >
< 输入 类型 = hidden name = 执行 = 搜索 / >
< 输入 类型 = 隐藏 name = subaction value = search / >
< 输入 name = story id = story type = < span class =code-keyword> text / >
< 按钮 类型 = 提交 > 搜索< / button >
< / form >



现在,我希望当用户在母版页中搜索时,搜索结果会在新的search.aspx页面上打开。我可以做这项工作吗?谢谢


i)把搜索条件,如果短到查询字符串或者将它们添加到会话变量。

ii)现在重定向到特定页面,即search.aspx这里。

iii)现在加载搜索页面从查询字符串或会话变量中获取搜索条件值,并执行搜索操作以在搜索结果的同一页面中填充网格。



希望他的帮助。


i)将搜索条件放入查询字符串中,或​​者将它们添加到会话变量中。

ii)现在重定向到特定的页面即search.aspx这里。



例如: -

 Response.Redirect( 〜/ SearchResult.aspx?name = smruti); 





iii)现在加载搜索页面时,从查询字符串或会话变量中获取搜索条件值,然后执行搜索操作,在搜索结果的同一页面中填充网格。



例如: -

 受保护  void  Page_Load( object  sender,EventArgs e)
{
string name = string .Empty;
if (Request.QueryString [ name ]!= null
{
name = Request.QueryString [ name]。ToString();
}

// 使用name的值进行搜索操作我们从查询字符串中获取。
// 然后将网格与您获得的结果数据绑定来自数据库
}







希望他的帮助。


On my search.aspx I'm using a Grid View to display search results:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" Width="735px">

        <Columns>
            <asp:BoundField DataField="title" HeaderText="title" SortExpression="title"></asp:BoundField>
            <asp:BoundField DataField="fcontents" HeaderText="fcontents" SortExpression="fcontents"></asp:BoundField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:minusConnectionString %>" SelectCommand="SELECT [title], [fcontents] FROM [tpost] WHERE ([fcontents] LIKE '%' + @fcontents + '%')">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="fcontents" PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>


and it works fine and the search results are displayed in the search.aspx page(I use grid view wizard for search results)
And in Master Page i use this code;

<div style="margin-removed 5px; float: left">
    <form name="searchform" method="get" class="searchform">
        <input type="hidden" name="do" value="search" />
        <input type="hidden" name="subaction" value="search" />
        <input name="story" id="story" type="text" />
        <button type="submit">search</button>
    </form>


Now, I want when a user search in the Master Page, the search results are opened on the new search.aspx page.how can I do this work?thanks

解决方案

ConnectionStrings:minusConnectionString %>" SelectCommand="SELECT [title], [fcontents] FROM [tpost] WHERE ([fcontents] LIKE '%' + @fcontents + '%')"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="fcontents" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div>


and it works fine and the search results are displayed in the search.aspx page(I use grid view wizard for search results)
And in Master Page i use this code;

<div style="margin-removed 5px; float: left">
    <form name="searchform" method="get" class="searchform">
        <input type="hidden" name="do" value="search" />
        <input type="hidden" name="subaction" value="search" />
        <input name="story" id="story" type="text" />
        <button type="submit">search</button>
    </form>


Now, I want when a user search in the Master Page, the search results are opened on the new search.aspx page.how can I do this work?thanks


i) Put the search criteria if short into query string or else add them to session variable.
ii) Now redirect to the particular page i.e. search.aspx here.
iii) Now on load of the search page get the search criteria values from query string or the session variable and do the search operation to populate the grid in the same page with the search results.

Hope his will be of help.


i) Put the search criteria if short into query string or else add them to session variable.
ii) Now redirect to the particular page i.e. search.aspx here.

Ex :-

Response.Redirect("~/SearchResult.aspx?name=smruti");



iii) Now on load of the search page get the search criteria values from query string or the session variable and do the search operation to populate the grid in the same page with the search results.

Ex :-

protected void Page_Load(object sender, EventArgs e)
        {
            string name = string.Empty;
            if(Request.QueryString["name"] != null)
            {
                name = Request.QueryString["name"].ToString();
            }

            // Do the search operation by using the value for name what we got from query            string.
            // then bind the grid with the result data you got from database
        }




Hope his will be of help.


这篇关于如何在单独的页面上显示搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆