Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-08-21
3
Medium Priority
?
683 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

704 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