使用复选框和文本框在gridview中搜索 [英] search in gridview with checkbox and textbox

查看:82
本文介绍了使用复选框和文本框在gridview中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个网格视图,其中包括两个布尔值和字符串字段,并且我希望通过一个复选框和一个文本框分别在此网格中进行搜索.
我使用sqlDataSource,但是因为当我使用一个sqlDataSource用于条件之间的网格与"(因为我当然也使用向导也或"运算符不能提供更好的结果),结果变得错误;
这是我的代码

 <   asp:SqlDataSource     ID   ="     runat   =" 服务器" 
 
                     span>    ConnectionString   ="  <% $ ConnectionStrings:mConnectionString%>" 
 
                   span>   
 
                     span>    SelectCommand   ="  <   SelectParameters  > 
            <   asp:ControlParameter     ControlID   ="  名称  主题"  PropertyName   文本" 
 
                     span>               类型  字符串" / > 
            <   asp:ControlParameter     ControlID   ="  名称  状态" 
 
                     span>               属性名称  已选中" 类型  ="    / > 
        <  /SelectParameters  > 
    <  /asp:SqlDataSource  >  


我希望gridview在复选框选中时以及文本框填充时显示它具有布尔字段的记录,而我按按钮网格时则显示与文本框内容相同的记录.
如果存在更好的解决方案,我将不坚持使用sqldatasource,但我接受它
请帮我它的力量
非常感谢您的答复

解决方案

ConnectionStrings:mConnectionString%>" span> span> SelectCommand =" < SelectParameters > < asp:ControlParameter ControlID =" 名称 主题" PropertyName 文本" span> 类型 字符串" / > < asp:ControlParameter ControlID =" 名称 状态" 属性名称 已选中" 类型 =" / > < /SelectParameters > < /asp:SqlDataSource >


我希望gridview在复选框选中时以及文本框填充时显示它具有布尔字段的记录,而我按按钮网格时则显示与文本框内容相同的记录.
如果存在更好的解决方案,我将不坚持使用sqldatasource,但我接受它
请帮我它的力量
非常感谢您的答复


您可以在表单加载时从后面的代码传递SqlCommand.

然后在复选框选中的事件中重新查询具有布尔字段的SqlCommand

并在文本框keypress事件中重新查询SqlCommand以获取文本框中的单词.

并显示网格.

希望对您来说清楚.


hi i have a grid view that it include two boolean and string field and i wannna search in this grid via a checkbox and a textbox separately .
i use sqlDataSource but becuse of when i use of one sqlDataSource for a grid perch "AND" between to condition (because of i use wizard of course also "or" operator cant supply better result )and result become wrong;
it is my code

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 

        ConnectionString="<%$ ConnectionStrings:mConnectionString %>" 

        

        SelectCommand="SELECT * FROM [category] WHERE (([subject] = @subject) AND ([status] = @status))">
        <SelectParameters>
            <asp:ControlParameter ControlID="title" Name="subject" PropertyName="Text" 

                Type="String" />
            <asp:ControlParameter ControlID="RadioButton1" Name="status" 

                PropertyName="Checked" Type="Boolean" />
        </SelectParameters>
    </asp:SqlDataSource>


i want gridview show the recordes that it has boolean field when chek box tick and when textbox fill and i press the button grid show the recordes that are equal with text box content.
iam not persistent to use sqldatasource if exist better solution i accept it
please help me its force
thanks a lot for reply

解决方案

ConnectionStrings:mConnectionString %>" SelectCommand="SELECT * FROM [category] WHERE (([subject] = @subject) AND ([status] = @status))"> <SelectParameters> <asp:ControlParameter ControlID="title" Name="subject" PropertyName="Text" Type="String" /> <asp:ControlParameter ControlID="RadioButton1" Name="status" PropertyName="Checked" Type="Boolean" /> </SelectParameters> </asp:SqlDataSource>


i want gridview show the recordes that it has boolean field when chek box tick and when textbox fill and i press the button grid show the recordes that are equal with text box content.
iam not persistent to use sqldatasource if exist better solution i accept it
please help me its force
thanks a lot for reply


You can pass the SqlCommand from code behind on form load.

And in the checkbox checked event requery the SqlCommand which has the boolean field

And in textbox keypress event requery the SqlCommand for the word in the textbox.

And display the grid.

Hope it is clear to you.


这篇关于使用复选框和文本框在gridview中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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