I have the following xml file:
<?xml version="1.0"?>
<faq>
<category categoryName="Search">
<subCategory subCategoryName="Search sub1">
<faqQuestion>
<faqQuestionId>1</faqQuestionId>
<question>What happens if..?</question>
<answer>Nothing..</answer>
<visible>true</visible>
<dateCreated>2005-09-15</dateCreated>
</faqQuestion>
</subCategory>
<subCategory subCategoryName="Search sub2">
<faqQuestion>
<faqQuestionId>1</faqQuestionId>
<question>How can I..?</question>
<answer>Do like this..</answer>
<visible>true</visible>
<dateCreated>2005-09-15</dateCreated>
</faqQuestion>
</subCategory>
<noSubCategory>
<noSubFaqQuestion>
<noSubQuestion>How can I..?</noSubQuestion>
<noSubAnswer>Do like this..</noSubAnswer>
<noSubVisible>true</noSubVisible>
<noSubDateCreated>2005-09-15</noSubDateCreated>
</noSubFaqQuestion>
</noSubCategory>
</category>
</faq>
I want to output this to an asp.net page using repeaters but I can't seem to get it working.
I have this in my aspx file:
<table border="0" cellpadding="0" cellspacing="0">
<asp:repeater id="rptCategory" runat="server">
<itemtemplate>
<tr>
<td><b><%# DataBinder.Eval(Container.DataItem, "categoryName") %></b></td>
</tr>
<asp:Repeater ID="rptSubCategory" Runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "subCategoryName")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</itemtemplate>
</asp:repeater>
</table>
This is in my code behind:
public class xmlut : System.Web.UI.Page
{
protected Repeater rptCategory;
protected Repeater rptSubCategory;
private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(MapPath("textfile1.xml"));
rptCategory.DataSource = ds;
rptCategory.DataBind();
}
private void rptCategory_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem) )
{
rptSubCategory = (Repeater) item.FindControl("rptSubCategory");
DataRowView drv = (DataRowView)item.DataItem;
rptSubCategory.DataSource = drv.CreateChildView("category_subCategory");
//rptSubCategory.DataSource = drv;
rptSubCategory.DataBind();
}
}
It seems like I don't get a relationship working. I've stepped through the code and the dataset automatically sets up the relationship when getting a xml file.
Any help? I'm going crazy!
<?xml version="1.0"?>
<faq>
<category categoryName="Search">
<subCategory subCategoryName="Search sub1">
<faqQuestion>
<faqQuestionId>1</faqQuestionId>
<question>What happens if..?</question>
<answer>Nothing..</answer>
<visible>true</visible>
<dateCreated>2005-09-15</dateCreated>
</faqQuestion>
</subCategory>
<subCategory subCategoryName="Search sub2">
<faqQuestion>
<faqQuestionId>1</faqQuestionId>
<question>How can I..?</question>
<answer>Do like this..</answer>
<visible>true</visible>
<dateCreated>2005-09-15</dateCreated>
</faqQuestion>
</subCategory>
<noSubCategory>
<noSubFaqQuestion>
<noSubQuestion>How can I..?</noSubQuestion>
<noSubAnswer>Do like this..</noSubAnswer>
<noSubVisible>true</noSubVisible>
<noSubDateCreated>2005-09-15</noSubDateCreated>
</noSubFaqQuestion>
</noSubCategory>
</category>
</faq>
I want to output this to an asp.net page using repeaters but I can't seem to get it working.
I have this in my aspx file:
<table border="0" cellpadding="0" cellspacing="0">
<asp:repeater id="rptCategory" runat="server">
<itemtemplate>
<tr>
<td><b><%# DataBinder.Eval(Container.DataItem, "categoryName") %></b></td>
</tr>
<asp:Repeater ID="rptSubCategory" Runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "subCategoryName")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</itemtemplate>
</asp:repeater>
</table>
This is in my code behind:
public class xmlut : System.Web.UI.Page
{
protected Repeater rptCategory;
protected Repeater rptSubCategory;
private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(MapPath("textfile1.xml"));
rptCategory.DataSource = ds;
rptCategory.DataBind();
}
private void rptCategory_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem) )
{
rptSubCategory = (Repeater) item.FindControl("rptSubCategory");
DataRowView drv = (DataRowView)item.DataItem;
rptSubCategory.DataSource = drv.CreateChildView("category_subCategory");
//rptSubCategory.DataSource = drv;
rptSubCategory.DataBind();
}
}
It seems like I don't get a relationship working. I've stepped through the code and the dataset automatically sets up the relationship when getting a xml file.
Any help? I'm going crazy!