如何在运行时加载带有Xml文件内容的Datagridview? [英] How Can I Load A Datagridview With The Contents Of A Xml File At Runtime ?
本文介绍了如何在运行时加载带有Xml文件内容的Datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个.xml文件,其中包含datagridview的数据。我想在运行时将相同的文件加载到datagridview中。此文件包含复选框,tetxbox和comboBox的值。
P.S. datagridview也应该在运行时在已经存在的TabControl下的TabPage中创建。
任何人都可以帮我一些想法......
感谢您的帮助:)
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 :)
推荐答案
您好朋友,您可以尝试这样的方式:
在您希望动态显示控件的页面上添加PlaceHolder
控件:
Hello friend, You may try something like this:
Add aPlaceHolder
control on your page where you want to display the control dynamically:
<asp:placeholder id="PlaceHolder1" runat="server" xmlns:asp="#unknown"></asp:placeholder>
编写以下代码:
Write the following code behind:
//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);
这篇关于如何在运行时加载带有Xml文件内容的Datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文