Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: cannot bind to a method result in a repeating control


Message #1 by "Chris H" <chris@h...> on Wed, 3 Jul 2002 21:39:43
Yes iam working on some project's and coding like u but 2 two day's i just 
cannot figure it out how it comes. and iam appreciate u that give some 
solutions. 

Please .net team explain this bugs (IS it true this is a .net bug ???)
Thank you.



> Hi all. 
T> his is a la chapter 7, around page 301 of Wrox Pro ASP.NET 2nd ed.
H> aving trouble with binding to a method in a DataList control when I 
p> erform the DataBind() call within my code behind class.  All works as 
e> xpected when I don't use code behind.  Any help is much appreciated. 

> I am rebuilding the project in vs.net after every change

> ========================
.> ..This fails with "System.Web.HttpCompileException: External component 
has
t> hrown an exception."
=> =======================
m> y.aspx
-> --------
<> @ Page language="c#" Codebehind="my.aspx.cs" AutoEventWireup="false"
I> nherits="my" %>
<> html>
<> body>
<> asp:DataList id="DataList1" runat="server">
 >    <ItemTemplate>
 >        <%# MyMethod() %>
 >    </ItemTemplate>
<> /asp:DataList>
<> /body>
<> /html>

> ------
m> y.aspx.cs
-> -----
u> sing System.Web.UI;
u> sing System.Collections;

> public class my : System.Web.UI.Page{

>     string MyMethod(){
 >        return "Mr. Magoo";
 >    }

>     void Page_Load(Object sender, EventArgs e) {
 >        ArrayList ary = new ArrayList();
 >        art.Add("Microsoft");
 >        ary.Add("Sun");
 >        DataList1.DataSource = ary;
 >        Page.DataBind();
 >    }

> }

> 
=> =======================
.> ...This works...
=> =======================
<> @ Page language="c#" %>
<> html>
<> body>
<> asp:DataList id="DataList1" runat="server">
 >    <ItemTemplate>
 >        <%# MyMethod() %>
 >    </ItemTemplate>
<> /asp:DataList>
<> /body>
<> /html>
<> script language="c#" runat="server">
 >    string MyMethod(){
 >        return "Mr. Magoo";
 >    }

>     void Page_Load(Object sender, EventArgs e) {
 >        ArrayList ary = new ArrayList();
 >        art.Add("Microsoft");
 >        ary.Add("Sun");
 >        DataList1.DataSource = ary;
 >        Page.DataBind();
 >    }
<> /script>

> 


  Return to Index