Hi,
I would like to generate columns in my RadGrid as I have in my DataTable. I created my DataTable about XML file. The structure of XML file you can see below:
<?xml version="1.0" encoding="utf-8" ?>
<Tabela>
<Colunas>
<Coluna NomeColuna="nome_completo" NomeCabecalho="Nome"></Coluna>
<Coluna NomeColuna="matricula" NomeCabecalho="Registro"></Coluna>
<Coluna NomeColuna="tipo_deficiencia" NomeCabecalho="Deficiência"></Coluna>
</Colunas>
<Linhas>
<Linha NomeColuna="nome_completo" Conteudo="João"></Linha>
<Linha NomeColuna="matricula" Conteudo="123456"></Linha>
<Linha NomeColuna="tipo_deficiencia" Conteudo="FÃsica"></Linha>
<Linha NomeColuna="nome_completo" Conteudo="Maria"></Linha>
<Linha NomeColuna="matricula" Conteudo="654321"></Linha>
<Linha NomeColuna="tipo_deficiencia" Conteudo="Auditiva"></Linha>
</Linhas>
</Tabela>
In a code aspx, I have the code in a button, as you can see below:
try
{
System.Data.DataSet _dsDadosXML = new System.Data.DataSet();
System.Data.DataTable _dtTabela = new System.Data.DataTable("Dados");
System.Data.DataRow _drLinhas;
_dsDadosXML.ReadXml(Server.MapPath("~/Protegidos/Empresas/Relatorios/XMLFile.xml"));
System.Data.DataTable _dtTabelaXML = _dsDadosXML.Tables["Coluna"];
foreach (System.Data.DataRow linha in _dtTabelaXML.Rows)
{
System.Data.DataColumn _dcColunas = new System.Data.DataColumn();
_dcColunas.ColumnName = linha[0].ToString();
_dcColunas.Caption = linha[1].ToString();
_dtTabela.Columns.Add(_dcColunas);
}
_dtTabelaXML = _dsDadosXML.Tables["Linha"];
foreach (System.Data.DataRow linha in _dtTabelaXML.Rows)
{
_drLinhas = _dtTabela.NewRow();
_drLinhas[linha[0].ToString()] = linha[1].ToString();
_dtTabela.Rows.Add(_drLinhas);
}
RadGrid1.DataSource = _dtTabela;
RadGrid1.DataBind();
}
catch (Exception ex)
{
lblResultado.Text = ex.Message;
}
And my RadGrid in source aspx is:
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Telerik"
GridLines="None" AllowPaging="true" AllowSorting="true" Width="97%"
AutoGenerateColumns="false" ShowStatusBar="true"
PageSize="10">
<HeaderContextMenu Skin="WebBlue">
<CollapseAnimation Type="OutQuint" Duration="200" />
</HeaderContextMenu>
<MasterTableView GridLines="None" Width="100%" CommandItemDisplay="None"
Font-Bold="false" Font-Italic="false" Font-Overline="false" Font-Strikeout="false"
Font-Underline="false" Name="TableViewTeste">
<PagerStyle NextPageText="Próximo" PrevPageText="Anterior" />
</MasterTableView>
<FilterMenu Skin="WebBlue">
<CollapseAnimation Type="InOutQuint" Duration="200" />
</FilterMenu>
<StatusBarSettings LoadingText="Aguarde..." ReadyText="Pronto" />
</telerik:RadGrid>
So, after to pass the DataBind method, I can't see anything in my RadGrid, that is, the data wasn't populated . Is there anything wrong with the code or other part?
I would like to generate columns in my RadGrid as I have in my DataTable. I created my DataTable about XML file. The structure of XML file you can see below:
<?xml version="1.0" encoding="utf-8" ?>
<Tabela>
<Colunas>
<Coluna NomeColuna="nome_completo" NomeCabecalho="Nome"></Coluna>
<Coluna NomeColuna="matricula" NomeCabecalho="Registro"></Coluna>
<Coluna NomeColuna="tipo_deficiencia" NomeCabecalho="Deficiência"></Coluna>
</Colunas>
<Linhas>
<Linha NomeColuna="nome_completo" Conteudo="João"></Linha>
<Linha NomeColuna="matricula" Conteudo="123456"></Linha>
<Linha NomeColuna="tipo_deficiencia" Conteudo="FÃsica"></Linha>
<Linha NomeColuna="nome_completo" Conteudo="Maria"></Linha>
<Linha NomeColuna="matricula" Conteudo="654321"></Linha>
<Linha NomeColuna="tipo_deficiencia" Conteudo="Auditiva"></Linha>
</Linhas>
</Tabela>
In a code aspx, I have the code in a button, as you can see below:
try
{
System.Data.DataSet _dsDadosXML = new System.Data.DataSet();
System.Data.DataTable _dtTabela = new System.Data.DataTable("Dados");
System.Data.DataRow _drLinhas;
_dsDadosXML.ReadXml(Server.MapPath("~/Protegidos/Empresas/Relatorios/XMLFile.xml"));
System.Data.DataTable _dtTabelaXML = _dsDadosXML.Tables["Coluna"];
foreach (System.Data.DataRow linha in _dtTabelaXML.Rows)
{
System.Data.DataColumn _dcColunas = new System.Data.DataColumn();
_dcColunas.ColumnName = linha[0].ToString();
_dcColunas.Caption = linha[1].ToString();
_dtTabela.Columns.Add(_dcColunas);
}
_dtTabelaXML = _dsDadosXML.Tables["Linha"];
foreach (System.Data.DataRow linha in _dtTabelaXML.Rows)
{
_drLinhas = _dtTabela.NewRow();
_drLinhas[linha[0].ToString()] = linha[1].ToString();
_dtTabela.Rows.Add(_drLinhas);
}
RadGrid1.DataSource = _dtTabela;
RadGrid1.DataBind();
}
catch (Exception ex)
{
lblResultado.Text = ex.Message;
}
And my RadGrid in source aspx is:
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Telerik"
GridLines="None" AllowPaging="true" AllowSorting="true" Width="97%"
AutoGenerateColumns="false" ShowStatusBar="true"
PageSize="10">
<HeaderContextMenu Skin="WebBlue">
<CollapseAnimation Type="OutQuint" Duration="200" />
</HeaderContextMenu>
<MasterTableView GridLines="None" Width="100%" CommandItemDisplay="None"
Font-Bold="false" Font-Italic="false" Font-Overline="false" Font-Strikeout="false"
Font-Underline="false" Name="TableViewTeste">
<PagerStyle NextPageText="Próximo" PrevPageText="Anterior" />
</MasterTableView>
<FilterMenu Skin="WebBlue">
<CollapseAnimation Type="InOutQuint" Duration="200" />
</FilterMenu>
<StatusBarSettings LoadingText="Aguarde..." ReadyText="Pronto" />
</telerik:RadGrid>
So, after to pass the DataBind method, I can't see anything in my RadGrid, that is, the data wasn't populated . Is there anything wrong with the code or other part?