Click here to Skip to main content
15,669,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an assignment where I am making a rss reader. I have a search text box that allows the user to enter a word and then click a button to search for those key words. The hard coded example search for "asp". I can't figure out how to pass my textbox variable into that string. Any help would be great!

string sTmp = "";
    string sSearch = "";

    //gets the value from the text box
    sSearch = txtSearch.Text;

    //hard coded sample give to me. it works.
    sTmp = "[contains(title, 'asp']";

    //my attempt at passing the variable above to the sTmp variable.
    //I have tried several variations of this with no luck
    sTmp = "[contains(title, 'sSearch']";


    xmlDViewOne.DataFile = @"rss.xml";
    xmlDViewOne.XPath = @"rss/channel/item " + sTmp;

    dtlDisplay.DataSource = xmlDViewOne;

Thanks in advance,

1 solution

Lookup string concatenation;
sTmp = "[contains(title, '" + sSearch + "']";

Take note though that if someone enters an apostrophe in the search term it will cause errors so you may want to also look up "escape characters".
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900