帮助我..我遇到问题我试图访问节点和ID,并在文本框中写一个数字,然后用价格计算。 [英] Help Me.. I Got Problems With im trying to access node by and id, and write a number in a textbox and then count it with the price.

查看:114
本文介绍了帮助我..我遇到问题我试图访问节点和ID,并在文本框中写一个数字,然后用价格计算。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中加载了一个xml文档,我试图通过计数来获取节点。我的问题是它只需要循环中的最后一个节点。节点有一个名为2的id,但我的计数从0开始。所以它在两个节点上混淆。我想要的是输入表单值与nodeA [AddonPrice]计数.IndialText由id,因为我有多个节点。



XmlDocument doc = new XmlDocument();

doc.Load(Server.MapPath(./ xmlRe /+ filenDato +) .xml));



int antalAdd0;

int ansver;

int pris;

int total = 0;



XmlNodeList nodeListADDon1 = doc.SelectNodes(TourInfo / AddOns / AddOn);

litTotal.Text =;

string addon =;

XmlAttribute xKey = doc.CreateAttribute(Id);

int count = 0;

int adID = 0;

xKey.Value =addon+ adID;

addon = Request.Form [ txtAddonAntal+ count];

antalAdd0 = int.Parse(addon.ToString());



foreach(nodeListADDon1中的XmlNode nodeA)

{





nodeA.Attributes.Append(xKey);

pris = int.Parse(nodeA [AddonPrice]。Inne rText);



ansver = antalAdd0 * pris;

litAdd.Text =++++

+ nodeA [AddonText]。InnerText + + antalAdd0.ToString()+ 价格:  + ansver.ToString()+  kr

;



总计+ = ansver;

litTotal.Text + = total.ToString()+  kr;

i got a xml document im loading in C#, and im trying to get nodes by count. My problem is it only takes the last node in the loop. The nodes has an id called 2 but my count start at 0. so it jumbs over two nodes. The thing i want is input form value counting with nodeA["AddonPrice"].InnerText by id because i have multible nodes.

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("./xmlRe/" + filenDato + ".xml"));

int antalAdd0;
int ansver;
int pris;
int total = 0;

XmlNodeList nodeListADDon1 = doc.SelectNodes("TourInfo/AddOns/AddOn");
litTotal.Text = "";
string addon = "";
XmlAttribute xKey = doc.CreateAttribute("Id");
int count = 0;
int adID = 0;
xKey.Value = "addon" + adID;
addon = Request.Form["txtAddonAntal" + count];
antalAdd0 = int.Parse(addon.ToString());

foreach (XmlNode nodeA in nodeListADDon1)
{


nodeA.Attributes.Append(xKey);
pris = int.Parse(nodeA["AddonPrice"].InnerText);

ansver = antalAdd0 * pris;
litAdd.Text = "" + "" + "" + "" + "

" + nodeA["AddonText"].InnerText + "" + antalAdd0.ToString() + "Pris: " + ansver.ToString() + " kr

";

total += ansver;
litTotal.Text += total.ToString() + " kr";

推荐答案

total + = ansver; 应该在foreach循环中,在'}'之上





你在循环中有一些带有赋值的计数,例如 ansver = antalAdd0 * pris; 。每个循环都会分配一个数字,但没有任何东西加在一起。



如果你想要一笔金额,那么你需要在某个循环中使用+ =



如果你只在循环中使用'=',那么每个循环都会覆盖之前循环设置的内容。



你使用取决于你想要做什么。



如果仍然无效,请点击改善问题按钮并展开您的问题。更多的是我在C#中加载了一个xml文档,我试图按计数获取节点。但它只选择最后一个节点会有所帮助。



解释你需要什么节点,它是什么价值类型以及如何计算它。



看起来你非常接近你需要的东西
total += ansver; should be within the foreach loop, above the '}'


You have some counts with assignments in the loops such as ansver = antalAdd0 * pris;. Each loop will assign a number but nothing is added together.

if you want a sum then you will need a += within the loop somewhere

if you only use '=' within the loop then each loop will overwrite what the previous loop set it as.

You use depends on what exactly you are trying to do.

If this is still not helpful then please click the "Improve Question" button and expand on your issue. More that "i got a xml document im loading in C#, and im trying to get nodes by count. but it only selectin last node" would be helpful.

Explain what node you need, what value type it is and how it should be calculated.

It looks like you are very close to what you need


这篇关于帮助我..我遇到问题我试图访问节点和ID,并在文本框中写一个数字,然后用价格计算。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆