DataList留言本回复后 Label显示数据

 protected void DataList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            ListItemType itemType = e.Item.ItemType;

            if (itemType == ListItemType.AlternatingItem || itemType == ListItemType.Item)
            {
                DataRowView tempRow = (DataRowView)e.Item.DataItem;
                int pid = Convert.ToInt32(tempRow.Row["id"].ToString());
                Label lbl = e.Item.FindControl("lblTXT") as Label;
                if (lbl != null)
                {
                    lbl.Text = tempRow.Row["Content"].ToString();
                    if (pid > 0)
                    {
                        DataSet ds = NoteBook.GetNoteReply(pid);
                        if (ds.Tables.Count > 0)
                        {
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                lbl.Text += "<p class=\"replay\"><span>回复内容:" + dr["Content"].ToString() + "</span><span>姓名:" + dr["Name"].ToString() + "</span><span>时间:" + dr["PubTime"].ToString() + "</span></p>";
                            }
                        }
                    }
                }
            }
        }

原文地址:https://www.cnblogs.com/xiaobaigang/p/824040.html