M
Musravus
Hi all,
I have a piece of XML that looks like this, which I want to DataBind
to a Repeater (the Repeater is inside a UserControl):
<SECTION id="MAIN" >
<SUBSECTION id="SUB1" />
<SUBSECTION id="SUB2" />
<SUBSECTION id="SUB3" />
</SECTION>
The Repeater definition looks like this:
<asp:Repeater id="rpt1" runat="server">
<ItemTemplate>
<asp:LinkButton id="lbtnSubSection" runat="server"
EnableViewState=False CommandName=<%#
((System.Xml.XmlNode)Container.DataItem).Attributes["id"].Value %>
OnCommand="LinkButton_SubSectionCommand"><%#
((System.Xml.XmlNode)Container.DataItem).Attributes["id"].Value
%></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
I bind the Repeater to the XmlNodeList using this code in
Page_PreRender:
XmlNodeList dataSourceNodeList =
myPieceOfXML.SelectNodes("SUBSECTION");
rpt1.DataSource = dataSourceNodeList;
rpt1.DataBind();
I have to do this in PreRender because the piece of XML may change
depending on a button I have clicked earlier, so I have to evaluate
this Click event before I can do the DataBind.
Once rendered the HTML looks like this:
<a id="uc1_rpt1__ctl1_lbtnSubSection"
href="javascript:__doPostBack('uc1$rpt1$_ctl1$lbtnSubSection','')">SUB1</a>
<a id="uc1_rpt1__ctl2_lbtnSubSection"
href="javascript:__doPostBack('uc1$rpt1$_ctl2$lbtnSubSection','')">SUB2</a>
<a id="uc1_rpt1__ctl3_lbtnSubSection"
href="javascript:__doPostBack('uc1$rpt1$_ctl3$lbtnSubSection','')">SUB3</a>
Upon postback it becomes clear that the CommandName property has not
been properly bound (e.CommandName evaluates to "") but the Text
property of the LinkButton has, even if they point to the same XML
attribute (id)! This does not happen if I put the code in Page_Load.
Why is this? Can anyone suggest a workaround?
Cheers, Eva
I have a piece of XML that looks like this, which I want to DataBind
to a Repeater (the Repeater is inside a UserControl):
<SECTION id="MAIN" >
<SUBSECTION id="SUB1" />
<SUBSECTION id="SUB2" />
<SUBSECTION id="SUB3" />
</SECTION>
The Repeater definition looks like this:
<asp:Repeater id="rpt1" runat="server">
<ItemTemplate>
<asp:LinkButton id="lbtnSubSection" runat="server"
EnableViewState=False CommandName=<%#
((System.Xml.XmlNode)Container.DataItem).Attributes["id"].Value %>
OnCommand="LinkButton_SubSectionCommand"><%#
((System.Xml.XmlNode)Container.DataItem).Attributes["id"].Value
%></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
I bind the Repeater to the XmlNodeList using this code in
Page_PreRender:
XmlNodeList dataSourceNodeList =
myPieceOfXML.SelectNodes("SUBSECTION");
rpt1.DataSource = dataSourceNodeList;
rpt1.DataBind();
I have to do this in PreRender because the piece of XML may change
depending on a button I have clicked earlier, so I have to evaluate
this Click event before I can do the DataBind.
Once rendered the HTML looks like this:
<a id="uc1_rpt1__ctl1_lbtnSubSection"
href="javascript:__doPostBack('uc1$rpt1$_ctl1$lbtnSubSection','')">SUB1</a>
<a id="uc1_rpt1__ctl2_lbtnSubSection"
href="javascript:__doPostBack('uc1$rpt1$_ctl2$lbtnSubSection','')">SUB2</a>
<a id="uc1_rpt1__ctl3_lbtnSubSection"
href="javascript:__doPostBack('uc1$rpt1$_ctl3$lbtnSubSection','')">SUB3</a>
Upon postback it becomes clear that the CommandName property has not
been properly bound (e.CommandName evaluates to "") but the Text
property of the LinkButton has, even if they point to the same XML
attribute (id)! This does not happen if I put the code in Page_Load.
Why is this? Can anyone suggest a workaround?
Cheers, Eva