Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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 …

772 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