[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

linq to sql "configure where expression"...how to

Posted on 2009-12-27
5
Medium Priority
?
642 Views
Last Modified: 2013-11-11
I am fairly new to VS and C#, and linq.  I am using VS 2008.  I have a c# web site with a listview and a linqdatasource.  This works fine now, it gets all the records in the table sorted by the quote column.  At the top of the page (before the listview), I have added a textbox and a button.  I want to enter in a value in the textbox and use this value to do a "contains" query\search of the first column of the listview (it's a column of quotes), and only return those rows that have that value\string in them.  I am not sure how to do this using the configure data source\configure data selection\where\configure where expression.  I know I select column:quote, operator:==...but I am unsure on the source, should it be querystring or control?  Beyond that, do I need to create code behind or not?  If a query string what is the syntax for this and where do I place it and how do I execute it (I was figuring that the button would kick this off).  If a control, again, what is the syntax and how do I execute it.  The first time that the page is displayed, the word "All", would be in the text property of the textbox, so that if the user did not change the value of the textbox, and the button was pushed, all the records would be gotten sorted by quotes (the way the page was originally working)
0
Comment
Question by:eelou
  • 4
5 Comments
 
LVL 5

Expert Comment

by:muhammadyasir
ID: 26130316
0
 

Author Comment

by:eelou
ID: 26133538
That is not very intuitive.  It does NOT answer my questions.
0
 

Author Comment

by:eelou
ID: 26135162
If I were to hazard a guess, my guess is that I would not name a data source and thus would not need a "configure where expression", instead I would do something like...http://www.codedigest.com/Articles/ASPNET/138_ListView_Control_with_LINQ_to_SQL_Class%E2%80%93_Part_2.aspx.  I will try this, it may be that I have answered my own question.  I am surprised at the lack of response to my question.  Did I word it incorrectly, not put it in the correct zones, or, is the subject matter still new to most people?
0
 

Author Comment

by:eelou
ID: 26155972
I decided to try to get the configured data source to work if I can.  I found this link...http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/652b723f-3a52-4f2f-abcd-b5ecb5d6424b/. The "Where="LastName.Contains(@SearchText)" does work, I just do not understand yet how to get the button part to work.  I think that this is tied into the   OnInit="LinqDataSource_Init" (in the first posting), which is some code behind code (but I do not know what might be in that code).  How is he refreshing the linqdatasource every time the button is pushed?
0
 

Accepted Solution

by:
eelou earned 0 total points
ID: 26196105
OK, I figured it out myself after a lot of soul (and internet) searching.  

*** Add "OnSelecting" to the linqdatasource...
        <asp:LinqDataSource ID="LinqDataSource1" runat="server"
            ContextTypeName="DataClassesDataContext" EnableDelete="True"
            EnableInsert="True" EnableUpdate="True" OrderBy="quote"
            TableName="rmquotes"
            OnSelecting="LinqDataSource1_Selecting" />

*** create LinqDataSource1_Selecting
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
  {

    DataClassesDataContext Db = new DataClassesDataContext();

    if (TextBox1.Text == "" || TextBox1.Text == " ")
    {
      var quotes =  (from q in Db.rmquotes
                     select new {q.quote, q.date , q.source , q.TempID});
      e.Result = quotes;
    }
    else
    {
      var quotes =  (from q in Db.rmquotes
                     where q.quote.Contains(TextBox1.Text)
                     select new {q.quote, q.date , q.source , q.TempID});
      e.Result = quotes;
    }

  }

*** rebind the linqdatasource to the list view when the button is clicked
protected void Button1_Click(object sender, EventArgs e)
  {
    ListView1.DataBind();
  }

 
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question