Can I use filter in asp:repeater?

走远了吗. 提交于 2019-12-11 02:07:17

问题


Can I use filter in repeater if Yes than How? it is possible in asp.net c# ?

In my project I put the filter for dynamic data in repeater.

see the example i want that type of filter in Repeater Click here


回答1:


Since your repeater is bound to a DataSource, you should apply the filter condition to it. For example, if the Datasource is represented by the SQLDataSource, please refer to the SqlDataSource.FilterExpression Property topic. This appears to be a client side filtering. If so the best solution would be to set the SQLDataSource.SelectCommand property so that it fetches required data from the DB. This will reduce the data size transferred from the DB Server to the WebServer and make your application work faster.




回答2:


What do you mean by "filter" ? I think you have to do it on your datasource.




回答3:


If you want to filter in the browser, then you need to use JavaScript to show and hide the main element for each Item.

If you are filtering on the server, you need to do the filtering on the DataSource to remove the entries you don't want and DataBind() the Repeater each time this changes. You can do the filtering manually using code, or use the FilterExpression if it is available as suggested by platon.




回答4:


The correct way is to filter your data on the data source, how ever in repeater you can also filter them and show them or not as:

<asp:Repeater ID="rMyID" runat="server">
  <ItemTemplate>
    <% if (Condition) { %>
      Show this line
    <%} %>
  </ItemTemplate>
</asp:Repeater>



回答5:


I think best way is using datatable filter property. Here is a simple example.

_dt = _dt.Select("COLUMN_NAME <> 'YOURFILTER'").CopyToDataTable();



来源:https://stackoverflow.com/questions/14196364/can-i-use-filter-in-asprepeater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!