aspx:
<asp:Repeater ID="rptProlist" runat="server" onitemdatabound="rptProlist_ItemDataBound"> <HeaderTemplate> <table border="0" class="infolist" cellpadding="0" cellspacing="0"> <thead> <tr> <th width="10%">开始日期</th> <th width="7%">创建人</th> <th width="7%">负责人</th> <th width="20%">参与人</th> </tr> </thead> </HeaderTemplate> <ItemTemplate> <tbody> <tr> <td><%#Eval("StartDate","{0:yyyy-MM-dd}")%></td> <td><%#returnUserRealName(Eval("ProjectCreater").ToString())%></td> <td><%#returnUserRealName(Eval("ProjectPrincipal").ToString())%></td> <td><asp:Label ID="lbPlayers" runat="server" Text=‘<%#Eval("ProjectPlayers") %>‘></asp:Label></td> </tr> </tbody> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
aspx.cs:
public string returnUserRealName(string data) { string[] ss = data.Split(‘,‘); string str = ""; foreach (string item in ss) { str += new PM.BLL.tb_User().GetModel(int.Parse(item)).UserRealName + ","; } str = str.Substring(0, str.Length - 1); return str; } protected void rptProlist_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { Label lb = (Label)e.Item.FindControl("lbPlayers"); string[] ss = lb.Text.Split(‘,‘); lb.Text = "";//清空重置之前的数据 foreach (string item in ss) { lb.Text += new PM.BLL.tb_User().GetModel(int.Parse(item)).UserRealName + ","; } lb.Text = lb.Text.Substring(0, lb.Text.Length - 1); } }