Binding XML from a data table to a DataGrid
Code Behind
string xml = null;
while(reader.Read()){
xml = reader["Responses"].ToString();
}
StringReader stream = new StringReader(xml);
using(DataSet ds = new DataSet()){
ds.ReadXml(stream, XmlReadMode.InferSchema);
ResultsDataGrid.DataSource = ds;
ResultsDataGrid.DataBind();
}
aspx page
<asp:datagrid id="ResultsDataGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="LABEL" HeaderText="Question"></asp:BoundColumn>
<asp:BoundColumn DataField="RESPONSE" HeaderText="Response"></asp:BoundColumn>
</Columns>
</asp:datagrid>
No comments:
Post a Comment