How to set a select criteria (Where Username != "ABC") in <asp.ObjectDataSource>? RRS feed

  • Question

  • User747696199 posted


    I'm working on a WebForms website application using c#. I need to add a select criteria in an existing <asp:ObjectDataSource>, but have not found how to do this. What I want to do is to select ONLY rows where username != "ABC"....

    Here is my current code in .aspx:

    <asp:ObjectDataSource ID=".." runat="server" SelectMethod="UICustomerSearch" FilterExpression="Select from TableA where @Username != 'ABC'" (I'm trying to add a select criteria here) .....>


             <asp:ControlParameter  ControlID="H_Fltr$txtFirstName"   Name="firstname" PropertyName="Text" Type="String">


             <asp:ControlParameter  ControlID="H_Fltr$txtUserName"   Name="username" PropertyName="Text" Type="String"> // Note: or should I do something here, add a select criteria in this line? I cannot use "DefaultValue=...." here, because I want to find the opposite, when a row's value for username field is NOT a certain value.



    I hope that I'm clear on what I want to achieve...Anyone have a suggestion?

    Thanks a lot!


    Sunday, June 2, 2013 5:03 PM

All replies

  • User-1716253493 posted
    use hiddenfield as control parameter. set in page_load event hiddenfield1.value=User.Identity.Name
    Sunday, June 2, 2013 7:14 PM
  • User747696199 posted

    Hi oned_gk,

    Thanks for the reply, but sorry I do not understand what you mean.

    Can you provide a few lines of code based on your suggestion? How to use hidden field as conyrol parameter (in.aspx), and what  to do in Page_Load?

    Keep in mind, I ONLY want the rows whose username is NOT "ABC"...so how do I specify that?



    Sunday, June 2, 2013 8:45 PM