none
QueryExtender 怎么指定搜索按钮 RRS feed

  • 问题

  • 昨天试用QueryExtender发现无法指定其搜索按钮.

    在页面放了三个Button,结果三个Button都能过滤数据
    看了官方文档,也没看到说怎么指定某Button为搜索按钮
    <body>
        <form id="form1" runat="server">
        <div>
            
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:Button ID="Button2" runat="server" Text="Button" />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="LinqDataSource1">
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                    <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                    <asp:BoundField DataField="Discount" HeaderText="Discount" SortExpression="Discount" />
                    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                    <asp:BoundField DataField="Hits" HeaderText="Hits" SortExpression="Hits" />
                    <asp:BoundField DataField="Sales" HeaderText="Sales" SortExpression="Sales" />
                    <asp:CheckBoxField DataField="Status" HeaderText="Status" SortExpression="Status" />
                </Columns>
            </asp:GridView>
            <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesFlowerDataContext" EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName="" TableName="Flower">
            </asp:LinqDataSource>
            <asp:QueryExtender ID="QueryExtender1" runat="server" TargetControlID="LinqDataSource1"  >
                <asp:SearchExpression DataFields="NAME" SearchType="StartsWith">
                    <asp:ControlParameter ControlID="TextBox1" />
                </asp:SearchExpression>
                <asp:RangeExpression DataField="Price" MaxType="Inclusive" MinType="Inclusive">
                    <asp:ControlParameter ControlID="TextBox2" />
                    <asp:ControlParameter ControlID="TextBox3" />
                </asp:RangeExpression>
            </asp:QueryExtender>
            <asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button3_Click" />
        </div>
        </form>
    </body>

    2016年5月24日 13:08

全部回复

  • Hi 段成华,

    你可以试下这段代码:

    Name: <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
    <asp:Button ID="Button1" runat="server" Text="Search" />
     //GridView code, Refer the code in previous section
    <asp:LinqDataSource ID="LinqDataSource1" runat="server"
     ContextTypeName="DataClassesDataContext" EntityTypeName="" TableName="Employees">
    </asp:LinqDataSource>
    <asp:QueryExtender ID="QueryExtender1" TargetControlID="LinqDataSource1" runat="server">
         <asp:SearchExpression DataFields="EmpName" SearchType="StartsWith">//DataFields对应gridview字段
             <asp:ControlParameter ControlID="txtName" />//ControlID对应检索框id
         </asp:SearchExpression>
    </asp:QueryExtender>

    参考链接:http://www.soaspx.com/dotnet/asp.net/Control/control_20091110_1488.html

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    2016年5月25日 6:22
  • Hello Moonlight Sheng,

    我俩的代码是基本一样的,只是你的代码中只有一个Button控件,如果你再放入一个Button,你就会发现这两个Button都能触发QueryExtender的搜索功能.

    2016年5月25日 11:23
  • Hi 段成华,

    要不你试下给他们用'ValidationGroup'属性进行下分组,参考链接:

    指定验证组

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    2016年5月26日 1:18
  • Hello Moonlight Sheng.

    我尝试了 ValidationGroup,依然没能起到作用。

    我之前在一篇QueryExtender的介绍文章的评论里面看到有人讨论了我这个问题。他们说是Postback的问题,任意一个ASP:Button都会引发Postback,而只要postback就会触发QueryExtender的搜索。

    我也估计这就是症结所在,但我依然不太清楚怎么解决这个问题。

    2016年5月27日 1:07
  • Hi,

    如果是asp按钮引起的postback的话,也许你可以尝试用input控件替换其他不需要提交的按钮,用js编写相关操作。

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2016年6月8日 7:10