Solved

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

Posted on 2010-08-21
3
680 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create and populate iFrame onClick of a button? 1 92
JQuery to parse xml string and get element by id 4 50
ebay devID, appID, certID, userToken 2 53
JSON  parse help 7 40
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 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