Dear sir,
New to ASP.NET, help will be appreciated.
I need to create a XML file for product feed. In our business, one product
always belongs to more than 1 categories. I need to have a XML file like.
<product id = "105">
<Name>whatever</Name>
<Categories>
<Category name = "Category1"/>
<Category name = "Category2"/>
....
</Categories>
</product
I can use a dataset which get the data from product table. However, my
question is that how can I get a sub set data of category. The category
rows varies depends on the product id. I am thinking to use dataview filter.
The following is my code.
......
dvCategory = New DataView(dtCategory)
strView = "ProductId='"&r("ProductId")&"'"
dvCategory.RowFilter= strView
For Each rCat in dvCategory.Table.Rows
Writer.WriteStartElement("category")
Writer.WriteAttributeString("name",
rCat("CatName")&r("ProductId"))
Writer.WriteEndElement()
Next
...
It will write out all the categories instead of only those categories this
product belongs to. Any idea what did I do wrong or how can I achieve this??
Thanks in advanced.
Guoqi Zheng
Tel: 0031-23-5343545
http://www.meetholland.comThis is because you are still grabbing all the rows from the underlying
table. The underlying table never changes, but the dataview can filter which
rows you see.
You should be looking at the Item property of the DataView to get each row
as filtered from the dataview instead.
"Guoqi Zheng" <no@.sorry.com> wrote in message
news:ulC57xn3DHA.1428@.TK2MSFTNGP12.phx.gbl...
> Dear sir,
> New to ASP.NET, help will be appreciated.
> I need to create a XML file for product feed. In our business, one product
> always belongs to more than 1 categories. I need to have a XML file like.
> <product id = "105">
> <Name>whatever</Name>
> <Categories>
> <Category name = "Category1"/>
> <Category name = "Category2"/>
> ....
> </Categories>
> </product>
> I can use a dataset which get the data from product table. However, my
> question is that how can I get a sub set data of category. The category
> rows varies depends on the product id. I am thinking to use dataview
filter.
> The following is my code.
> ......
> dvCategory = New DataView(dtCategory)
> strView = "ProductId='"&r("ProductId")&"'"
> dvCategory.RowFilter= strView
> For Each rCat in dvCategory.Table.Rows
> Writer.WriteStartElement("category")
> Writer.WriteAttributeString("name",
> rCat("CatName")&r("ProductId"))
> Writer.WriteEndElement()
> Next
> ...
> It will write out all the categories instead of only those categories this
> product belongs to. Any idea what did I do wrong or how can I achieve
this??
> Thanks in advanced.
> Guoqi Zheng
> Tel: 0031-23-5343545
> http://www.meetholland.com
Hi,
> For Each rCat in dvCategory.Table.Rows
> Writer.WriteStartElement("category")
> Writer.WriteAttributeString("name",
> rCat("CatName")&r("ProductId"))
> Writer.WriteEndElement()
> Next
> ...
> It will write out all the categories instead of only those categories this
> product belongs to. Any idea what did I do wrong or how can I achieve
this??
You should loop through DataView' DataRowView:
foreach (DataRowView drv in dv)
Write...(drv["name"]);
--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts
Saturday, March 31, 2012
subst command or maybe network access issue
I'm trying to open an xml document on my computer. It is on a subst drive
f. I get a System.IO.DirectoryNotFoundException when I try to open the
file. When I switch to the C drive it works fine. I gave aspnet user admin
right to make sure it wasn't a permission problem but I am still getting the
exception whatever I do unless I look at my C drive. Any idea what gives?
Thanks guys.
Chris"Chris" <cf@.NoSpamzieQuotepro.com> wrote in
news:e2H7fPO9DHA.2432@.TK2MSFTNGP10.phx.gbl:
> I'm trying to open an xml document on my computer. It is on a subst
> drive f. I get a System.IO.DirectoryNotFoundException when I try to
> open the file. When I switch to the C drive it works fine. I gave
> aspnet user admin right to make sure it wasn't a permission problem but
> I am still getting the exception whatever I do unless I look at my C
> drive. Any idea what gives?
Are the other drives you having trouble with by chance network drives?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
f. I get a System.IO.DirectoryNotFoundException when I try to open the
file. When I switch to the C drive it works fine. I gave aspnet user admin
right to make sure it wasn't a permission problem but I am still getting the
exception whatever I do unless I look at my C drive. Any idea what gives?
Thanks guys.
Chris"Chris" <cf@.NoSpamzieQuotepro.com> wrote in
news:e2H7fPO9DHA.2432@.TK2MSFTNGP10.phx.gbl:
> I'm trying to open an xml document on my computer. It is on a subst
> drive f. I get a System.IO.DirectoryNotFoundException when I try to
> open the file. When I switch to the C drive it works fine. I gave
> aspnet user admin right to make sure it wasn't a permission problem but
> I am still getting the exception whatever I do unless I look at my C
> drive. Any idea what gives?
Are the other drives you having trouble with by chance network drives?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Saturday, March 24, 2012
Sum of XML data
I am reading an XML file and writing its contents to a Repeater control using the following code:
Dim dstTS As DataSet
dstTS = New DataSet()
dstTS.ReadXml( MapPath( "cw052004.xml" ) )rptTS.DataSource = dstTS
rptTS.DataBind()
It works fine. However, I would also like to calculate the sum of a the "item_cost" from each node in the XML file and place it in a variable.
Can anybody suggest the best way to go about this?do some searching for examples on the itemdatabound event. this is fired everytime an item is bound and you can use this to sum up your grids and such.
Awesome, thanks!
Subscribe to:
Posts (Atom)