我基本上試圖做的是檢查在我的dropDownList1中選擇的值是否在我的XML文檔中,如果是這樣,則打印出它是胖內容。否則,我會返回字符串「對不起,我們找不到你的食物!」。現在,我只得到其他場景。任何幫助將是非常美妙的檢查在DropDownList中選擇了什麼值,並根據XML值檢查它
我的代碼如下:
XmlDocument xDoc = new XmlDocument();
xDoc.Load("the xml address");
// go through each food name (this works)
foreach (XmlNode name in xDoc.SelectNodes("Web_Service/Food/Name"))
{
//grab the string
string foodName = name.InnerText;
// what I'm tring to here is loop through the items in the dropdown list
// and check it against foodName
foreach (ListItem li in DropDownList1.Items)
{
if (li.Value == foodName)
{
// print the value fat value of that particular foodName
// address is ("Web_Service/Food/Fat")
}
else
{
TextBox2.Text = "sorry we could not find your food!";
}
}
}
希望我解釋的不夠好,謝謝你們。
這工作完美。 – Spamsational 2014-09-06 03:21:11