询问者
QueryExtender 怎么指定搜索按钮

问题
-
昨天试用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>
全部回复
-
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.
- 已编辑 Moonlight ShengMicrosoft contingent staff 2016年5月26日 1:19 错别字。。。
-
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.
- 已编辑 Moonlight ShengMicrosoft contingent staff 2016年5月26日 1:19
-
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.