Solved

.aspx.cs code for adding a textbox entry to "[contains(title, 'TextboxEntry']"

Posted on 2010-08-21
3
681 Views
Last Modified: 2013-11-18
I have a project which has a Search textbox for the user to enter keyword(s) to retrieve from an
.xml page called rss.xml.  In the .aspx.cs page I was instructed to do this by declaring a
string (sTemp) and sTemp = "[contains(title, 'asp')]" for example.  However, I now need to replace the
'asp' with whatever the user inputs into the textbox.  I've attached the back code that I'm using.
Any help would be GREATLY appreciated.
Thank you

protected void btnSearch_Click(object sender, EventArgs e)
        {
            string In = string.Empty;
            string SearchText =  txtSearch.Text;
            if (ddlSearchWhere.SelectedIndex == 0) -----this is from a dropdown list for the user to choose where they want their text searched----
                In  = "[contains(title,"+'txtSearch.Text')]";
            if (SearchText != null)
                SearchText = In;
                //In = "[contains(title, '" + SearchText;
            xmlDataSource1.DataFile = @"rss.xml";
            xmlDataSource1.XPath = @"rss/channel/item" + SearchText;// + sTemp;
            xmlDataSource1.DataBind();

            dtlDisplay.DataSource = xmlDataSource1;
            dtlDisplay.DataBind();

Open in new window

0
Comment
Question by:SinaBug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
GoJoeIsBlue earned 500 total points
ID: 33492986
Do you code compile?

If not one error can be found in the statement assigning to you "In" variable.
To be valid this should be: "[contains(title, '" + SearchText + "')]";

...but an even better alternative would be: "[contains(translate(title, 'ABCDEF...VWXYZ', 'abcdef...vwxyz') , '" + SearchText.ToLower() + "')]";
since this will make your search case insensitive.
0
 

Author Comment

by:SinaBug
ID: 33493050
I guess I'm not real sure what you mean by "code compile", but I did try your solution and it makes PERFECT SENSE to me and I would have thought it would run great (I tried both solutions)....however,
with the second solution, I got no response when I ran it.......the first solution gave me an "XPath Exception was unhandled by user code" error & underneath it says ..."'rss/channel/item[contains(title, 'now')]' "...... has an invalid token.
This is MUCH better than what I was getting because it's at least recognizing the word 'now' which I typed in for the search text.
Any other suggestions?
0
 

Author Closing Comment

by:SinaBug
ID: 33493423
I think there was an extra ( prior to "title" and that's why I was receiving the error, but all is FANTABULOUS ----- thank you sooooo much ----- I'm sold!!!!!!  SinaBug
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

739 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