Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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 …
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…
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:

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now