解决repeater中外键的代码

首先,托俩控件  HiddenField   和  label

   HiddenField 是用来保存数值, Label是用来在Repeater中显示数值

 1 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
 2     {
 3         if (e.Item.ItemIndex > -1)
 4         {
 5             HiddenField HiddenFieldNewsTyId = (HiddenField)e.Item.FindControl("HiddenFieldNewsTyId");
 6             Label LabelNewsTyName = (Label)e.Item.FindControl("LabelNewsTyName");
 7 
 8             if (HiddenFieldNewsTyId != null)
 9             {
10                 NewsType newstype = NewsTypeManager.SelectOne(Convert.ToInt32(HiddenFieldNewsTyId.Value));
11                 LabelNewsTyName.Text = newstype.NewsTypeName;
12             }
13         }
14     }

这样就轻松解决在repeater中不能显示外键的问题了!

posted @ 2012-04-10 09:07  Ruicky  阅读(227)  评论(0编辑  收藏  举报