日期:2014-05-18  浏览次数:20374 次

关于repeater控件!!!请看看我的代码
asp.net(c#)2.0 开发 webform

出现一个问题,请看下面的代码:
 .aspx中是这样写的:
  <asp:Repeater runat="server" id="GoodsKey">
  <headerTemplate>
  关键字:
  </headerTemplate>
  <ItemTemplate>
  <asp:label runat="server" text='<%#Eval("ItemName") %>'></asp:label>
  </ItemTemplate>
  </asp:Repeater>
 .aspx.cs中是这样写的:
  protected void Page_Load(object sender, EventArgs e)
  {
  //从XML中读取关键字
  GoodsKey.DataSource = KeysXml.GetXml(Server.MapPath("~/Keys.xml"));
  }

浏览网页的时候,一点显示也没有?请问这是为什么???

我断点调试了一下,“GoodsKey.DataSource”是取得到值的!

请指点一下,谢谢!!

------解决方案--------------------
少了绑定的语句吧,Object.Bind();
------解决方案--------------------
GoodsKey.DataSource = KeysXml.GetXml(Server.MapPath( "~/Keys.xml ")); 

还要加上

GoodsKey.DataBind();
------解决方案--------------------
GoodsKey.DataSource = KeysXml.GetXml(Server.MapPath( "~/Keys.xml "));
GoodsKey.DataBind(); //加上这句
------解决方案--------------------
别忘了在page_load里面加上if(!ispostback){}
GoodsKey.DataSource = KeysXml.GetXml(Server.MapPath( "~/Keys.xml ")); 
GoodsKey.DataBind();