如何将一个XML文件读入到一个datagrid中显示出来?最好源码,谢了 可参照:http://www.csdn.net/develop/read_article.asp?id=18940 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你先定义你的TablestyleMappingName 对应你的表名,列名等等然后DataSet ques=new DataSet();ques.ReadXml("Questions.xml");dataGrid1.DataSource=ques.Tables[0].DefaultView; 请问tableStyle如何定义,我其他的都知道就是不知道如何定义table啊 慢慢看去吧 TableStyle.MappingName = “表”...//应该显示的各列DataGridColumnStyle[] dgcolFounds;DataGridTextBoxColumn dgcolFound;//分别去new一个...dgcolFound.MappingName = "name";dgcolFound.HeaderText = "name";dgcolFounds[0] = dgcolFound;...//将定义的头填进去TableStyle.GridColumnStyles.AddRange(dgcolFounds);//获得数据源dgTemp.DataSource = dsTemp.Tables[0].DefaultView;dgTemp.TableStyles.Add(TableStyle);//上面的dsTemp懒得定义,自己定义就是了 =============*.aspx:<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 96px" runat="server"></asp:DataGrid>=============*.aspx.cs:using System.Xml;using System.IO;string filename=Server.MapPath("AA.xml");DataSet ds=new DataSet();ds.ReadXml(filename);this.DataGrid1.DataSource=ds.Tables[0].DefaultView ;this.DataGrid1.DataBind(); 在DataGrid的属性中可以设置的!你找一下 ********************************************************我的程序,看有什么错误DataSet ds=new DataSet();ds.ReadXml("test.xml");this.DataGrid1.DataSource=ds.Tables[0].DefaultView ;提示无法找到表0,怎么办? 可能是你的test.xml不符合DataSet的格式,而使DataSet中一个DataTable都没有,你可以用DataSet.SaveXml存一个xml文件比较一下格式。 [XML 文件]<Address_Table> <address> <name>dongdong</name> <Email>[email protected]</Email> <mobile>13912345678</mobile> <phone>67681234</phone> <home>XiTu City Road No.23</home> </address> <address> <name>xixi</name> <Email>[email protected]</Email> <mobile>13812345678</mobile> <phone>81234567</phone> <home>TaiLan Mansion No.1008 Room</home> </address> <address> <name>chai</name> <Email>[email protected]</Email> <mobile>13109876543</mobile> <phone>98768765</phone> <home>MaiLei Road No.8</home> </address></Address_Table>[C#] private void btnReadXML_Click(object sender, System.EventArgs e) { string filePath = "address.xml"; dsAddress.ReadXml(filePath); dataGrid1.DataSource = dsAddress; dataGrid1.DataMember = "address"; dataGrid1.CaptionText = dataGrid1.DataMember; } 关于单页排序问题 各位高手,小菜鸟请你们帮帮忙 一个反射的问题 如何访问远程ftp目录中的一个文件啊? 操作注册表的问题 C/S模式中,如果S端数据库的密码更改了,C端怎么处理? 用WebClient自动登陆csdn的问题 求OUTLOOK(像QQ面板)风格控件的源码 哪位大虾解释一下static类型变量和一般变量的区别,谢谢! socket问题 如何在DataGrid中删除一行 简单问题,DateTime.tostring(""),如何格式化保证为2003-12-30
DataSet ques=new DataSet();
ques.ReadXml("Questions.xml");
dataGrid1.DataSource=ques.Tables[0].DefaultView;
TableStyle.MappingName = “表”
...
//应该显示的各列
DataGridColumnStyle[] dgcolFounds;
DataGridTextBoxColumn dgcolFound;
//分别去new一个
...
dgcolFound.MappingName = "name";
dgcolFound.HeaderText = "name";
dgcolFounds[0] = dgcolFound;
...
//将定义的头填进去
TableStyle.GridColumnStyles.AddRange(dgcolFounds);
//获得数据源
dgTemp.DataSource = dsTemp.Tables[0].DefaultView;
dgTemp.TableStyles.Add(TableStyle);
//上面的dsTemp懒得定义,自己定义就是了
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 96px" runat="server"></asp:DataGrid>
=============*.aspx.cs:
using System.Xml;
using System.IO;string filename=Server.MapPath("AA.xml");DataSet ds=new DataSet();
ds.ReadXml(filename);
this.DataGrid1.DataSource=ds.Tables[0].DefaultView ;
this.DataGrid1.DataBind();
我的程序,看有什么错误
DataSet ds=new DataSet();
ds.ReadXml("test.xml");
this.DataGrid1.DataSource=ds.Tables[0].DefaultView ;
提示无法找到表0,怎么办?
<Address_Table>
<address>
<name>dongdong</name>
<Email>[email protected]</Email>
<mobile>13912345678</mobile>
<phone>67681234</phone>
<home>XiTu City Road No.23</home>
</address>
<address>
<name>xixi</name>
<Email>[email protected]</Email>
<mobile>13812345678</mobile>
<phone>81234567</phone>
<home>TaiLan Mansion No.1008 Room</home>
</address>
<address>
<name>chai</name>
<Email>[email protected]</Email>
<mobile>13109876543</mobile>
<phone>98768765</phone>
<home>MaiLei Road No.8</home>
</address>
</Address_Table>[C#]
private void btnReadXML_Click(object sender, System.EventArgs e)
{
string filePath = "address.xml";
dsAddress.ReadXml(filePath);
dataGrid1.DataSource = dsAddress;
dataGrid1.DataMember = "address";
dataGrid1.CaptionText = dataGrid1.DataMember;
}