I am semi new to XML This is done in VB
I am having trouble getting a datagrid to refresh data after the initial load of data from an XMLDataSource.
I have a textBox where I enter some information anda Button to send it to get an XML response file
I am making a request for an xml file.
Dim srResponse As
New StreamReader(...
I then write the result to a string
Dim OrderResp
As String = srResponse.ReadToEnd()
I then write the Text to a text field so I can see the contents
TxtResponse.Text = OrderResp
I then bind the data to an XMLdatasource (XMLResponse)(It's all formatted with a transform file as I need it)
XMLResponse.Data = OrderResp
XMLResponse.DataBind()
I then Bind the XMLDatasource to my Gridview
gvorders.DataSource = XMLResponse
gvorders.DataBind()
The first time I enter a value and submit the data everything works fine.
The second time I submit a new value the result Text field changes with new data but the Gridview stays the same.
I have tried..
Setting the Gridviews EnableViewState to FALSE
Clearing the datasource (on both the XMLDataSource and the datagrid) before the binding
gvorders.DataSource = ""
gvorders.DataBind()
gvorders.DataSource = XMLResponse
gvorders.DataBind()
I created a texfile (Trace file) that adds a timestamp between every transaction to see if it was being skipped for some reason and the trace file executes just fine.
I then started a new page and kept the basic elements and the gridview will only update once.
I also found that If I run a query a second time the text value will change correctly but the gridview keeps the old data. I then open the page in an editor. add a space somewhere on the design page and save (so that it will recompile the page) the new data
will then load in the gridview. I then do another query and the text changes but the grid stays the same.
I have to say that I am completely at a loss.....Is there something that I'm doing wrong? When I make a call for an XML file does all processing stop until it gets an answer? I thought that maybe the code contined while the page was waiting on the response
but if that was the case the text file would not update as well because I update that before I do the Gridview bid.
I ultimately want to save this to a database in a batch mode but if the data doesn't refresh I will be writing the same data over and over again.
The XmlDataSource, unlike any other datasource (ObjectDataSource, LinqDataSource, etc) has caching enabled by default. And not only that, the cache duration is set to 0 (infinite), also by default. It's pretty stupid, but a quite common issue with it.
When you create your XmlDataSource you have to disable caching.
XmlDataSource xds = new XmlDataSource();
xds.EnableCaching=false;
That should do the trick.
Remember: mark posts that helped you as the answer to aid future readers
BindGrid("http://www.emoove.com/rss/property-news.xml", _
GridView1, 3)
Sub BindGrid(ByVal strRss As String, ByVal oGrid _
As GridView, ByVal iTable As Integer)
Dim oDs As New Data.DataSet
oDs.ReadXml(strRss)
oGrid.DataSource = oDs.Tables(iTable)
oGrid.DataBind()
End Sub
If I was helpful, please mark "answered" so I can get credit. Thanks!
I assumed that it was a cacheing issue but I guess I was stumped because I was loading in new data to the XMLdatasource which I would assume would clear out the cache or force a reload since the data had changed. I think I also tried setting the text control
to the datasource.data and it changed but the grid did not. I will try your suggestion and hopefull this will solve my problem.
I'm doing all of this because I can't find an easier way to download an XML file and pull it into a database with all of the elements separated into a table not just the xml in one field. If anyone has an easier way to do this i'm all ears.
Not sure what database you are using, but I send lots of xml to SQL 2005, which has a great xml datatype. Then I can parse the xml in my stored procedure and put it where it needs to go or store the entire xml string into an xml column of a table for later
parsing.
Remember: mark posts that helped you as the answer to aid future readers
I am trying to update my XML file that is bound to the gridview but am not able to do it. I read on the web that Gridview doesn't automatically update the XMLDatasource and that we should write our own event handlers to updat it. I can get the selected
row from the grid, but how can I update the XML file with this data? How would I know which node corresponds to the selected row in the grid. Would some one be able to help me? Thanks a bunch for your help, in advace.
porterboy
Member
442 Points
185 Posts
XML to Gridview using Xmldatasource problem
May 16, 2008 08:03 PM|LINK
I am semi new to XML This is done in VB
I am having trouble getting a datagrid to refresh data after the initial load of data from an XMLDataSource.
I have a textBox where I enter some information anda Button to send it to get an XML response file
I am making a request for an xml file.
I then write the result to a stringDim srResponse As New StreamReader(...
Dim OrderResp As String = srResponse.ReadToEnd() I then write the Text to a text field so I can see the contents
TxtResponse.Text = OrderResp
I then bind the data to an XMLdatasource (XMLResponse)(It's all formatted with a transform file as I need it)
XMLResponse.Data = OrderResp
XMLResponse.DataBind()
I then Bind the XMLDatasource to my Gridview
gvorders.DataSource = XMLResponse
gvorders.DataBind()
The first time I enter a value and submit the data everything works fine.
The second time I submit a new value the result Text field changes with new data but the Gridview stays the same.
I have tried..
Setting the Gridviews EnableViewState to FALSE
Clearing the datasource (on both the XMLDataSource and the datagrid) before the binding
gvorders.DataSource = ""
gvorders.DataBind()
gvorders.DataSource = XMLResponse
gvorders.DataBind()
I created a texfile (Trace file) that adds a timestamp between every transaction to see if it was being skipped for some reason and the trace file executes just fine.
I then started a new page and kept the basic elements and the gridview will only update once.
I also found that If I run a query a second time the text value will change correctly but the gridview keeps the old data. I then open the page in an editor. add a space somewhere on the design page and save (so that it will recompile the page) the new data will then load in the gridview. I then do another query and the text changes but the grid stays the same.
I have to say that I am completely at a loss.....Is there something that I'm doing wrong? When I make a call for an XML file does all processing stop until it gets an answer? I thought that maybe the code contined while the page was waiting on the response but if that was the case the text file would not update as well because I update that before I do the Gridview bid.
I ultimately want to save this to a database in a batch mode but if the data doesn't refresh I will be writing the same data over and over again.
Any help wpuld be appreciated
whatispunk
Contributor
4074 Points
876 Posts
Re: XML to Gridview using Xmldatasource problem
May 17, 2008 07:37 AM|LINK
The XmlDataSource, unlike any other datasource (ObjectDataSource, LinqDataSource, etc) has caching enabled by default. And not only that, the cache duration is set to 0 (infinite), also by default. It's pretty stupid, but a quite common issue with it.
When you create your XmlDataSource you have to disable caching.
XmlDataSource xds = new XmlDataSource();
xds.EnableCaching=false;
That should do the trick.
Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
Bonekrusher
Contributor
4027 Points
922 Posts
Re: XML to Gridview using Xmldatasource problem
May 17, 2008 12:54 PM|LINK
Try this:
BindGrid("http://www.emoove.com/rss/property-news.xml", _ GridView1, 3) Sub BindGrid(ByVal strRss As String, ByVal oGrid _ As GridView, ByVal iTable As Integer) Dim oDs As New Data.DataSet oDs.ReadXml(strRss) oGrid.DataSource = oDs.Tables(iTable) oGrid.DataBind() End Subwhatispunk
Contributor
4074 Points
876 Posts
Re: XML to Gridview using Xmldatasource problem
May 17, 2008 05:28 PM|LINK
How does a DataSet deal with hierarchical data like xml? I never use them because they're such big ugly objects. Far too much overhead.
Just keep your code the same as it is, but add the xds.EnableCaching=false and all will be well.
Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
porterboy
Member
442 Points
185 Posts
Re: XML to Gridview using Xmldatasource problem
May 19, 2008 12:52 PM|LINK
I assumed that it was a cacheing issue but I guess I was stumped because I was loading in new data to the XMLdatasource which I would assume would clear out the cache or force a reload since the data had changed. I think I also tried setting the text control to the datasource.data and it changed but the grid did not. I will try your suggestion and hopefull this will solve my problem.
I'm doing all of this because I can't find an easier way to download an XML file and pull it into a database with all of the elements separated into a table not just the xml in one field. If anyone has an easier way to do this i'm all ears.
whatispunk
Contributor
4074 Points
876 Posts
Re: XML to Gridview using Xmldatasource problem
May 20, 2008 03:29 AM|LINK
Not sure what database you are using, but I send lots of xml to SQL 2005, which has a great xml datatype. Then I can parse the xml in my stored procedure and put it where it needs to go or store the entire xml string into an xml column of a table for later parsing.
Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
ravishr
Member
20 Points
6 Posts
Re: XML to Gridview using Xmldatasource problem
Dec 25, 2009 09:23 AM|LINK
http://rranjane.blogspot.com/
jyendapally
Member
4 Points
8 Posts
Re: XML to Gridview using Xmldatasource problem
Dec 30, 2009 03:23 PM|LINK
I am trying to update my XML file that is bound to the gridview but am not able to do it. I read on the web that Gridview doesn't automatically update the XMLDatasource and that we should write our own event handlers to updat it. I can get the selected row from the grid, but how can I update the XML file with this data? How would I know which node corresponds to the selected row in the grid. Would some one be able to help me? Thanks a bunch for your help, in advace.
chaitanya.vk
Member
4 Points
2 Posts
Re: XML to Gridview using Xmldatasource problem
Jan 04, 2010 07:01 AM|LINK
hi..
even i am facing the similar problem. can some one pls help me soon.
i have a XMLDataSource for which i mentioned the datafile to 'MyXml'.
In my page i have a textbox and a button 'add' for adding the text to the xml and display the same in the datagrid.
While displaying the xml data in the grid i used
grdDetails.DataSource = XmlDataSource1;
grdDetails.DataBind();
but wen i click that add button the data is getting updated in xml file and i can see that, but in the datagrid it is not getting updated.
pls help soon.thanx in advance.
chaitanya.vk
Member
4 Points
2 Posts
Re: XML to Gridview using Xmldatasource problem
Jan 04, 2010 07:03 AM|LINK
hi again...
i tried datasource caching with false...it didnt help me...
so please help me .....