Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have an .xml file which contains the data of a datagridview. I want to load the same file back into the datagridview at runtime.This file contains values of a checkbox, tetxbox and comboBox.

P.S. The datagridview should also be created at runtime in a TabPage under an already existing TabControl.

Can anyone help me with some ideas....
Thanks for helping :)
Posted
Comments
Richard MacCutchan 5-Jun-14 4:51am    
What sort of ideas? As I understand the issue you just need to read in the data from the XML file and populate the DataGridView with the apopropriate values and settings. What is the difficulty?
sovit agarwal 5-Jun-14 4:56am    
the difficulty is i need to create the datagridview at runtime depending on the contents of the XML file . The problem again here is the XML file contains some fields missing , and so these columns are not created
Richard MacCutchan 5-Jun-14 5:18am    
And how do you think we can help to fix the content of your XML file?
sovit agarwal 5-Jun-14 5:58am    
the XML file is created from the datagridview itself.
When i Click on a button called "SAVE as XML", the empty contents of the view are not taken into account. As a result of which during loading the entire datagridview is not generated.
So now how do i account for saving the datagridview along with the empty fields?
Richard MacCutchan 5-Jun-14 7:04am    
Well I'm afraid we cannot guess what your code does when you click that button.

1 solution

Hello friend, You may try something like this:

Add a PlaceHolder control on your page where you want to display the control dynamically:
ASP.NET
<asp:placeholder id="PlaceHolder1" runat="server" xmlns:asp="#unknown"></asp:placeholder>

Write the following code behind:
C#
//Code to read an XML file and populate a DataSet object
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/XMLFile1.xml"));

//Create a GridView control
GridView gv = new GridView();

//Set the DataSource property 
gv.DataSource = ds;
gv.DataBind();

//Add dynamically created GridView control to a PlaceHolder control
PlaceHolder1.Controls.Add(gv);
 
Share this answer
 
Comments
sovit agarwal 5-Jun-14 5:59am    
Thanks friend for your help but i am not using ASP. I am using WinForms...Can u help me with that?
Also i have no idea of placeholders...

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