我有一個RadGrid,它在其筆記列中顯示一個txtNote文本。我也有一個名爲lblShowAllSessionNotes的標籤。當會話筆記添加或添加到現有音符,ID類型郵票preceeds實際TXT消息,就像這樣:製作粗體顯示在RadGrid txtNote和標籤中的字符串
NoteTYPE - CommunicationType - ContactType 通過電子簽名:某人的名字6/12/2016 12:00:00 這是註釋文本。這是文字。
如果我在代碼中把...在字符串變量後面,然後在radgrid控件顯示爲:由電子簽名:某人的名字;而不是由以電子方式簽名:某人的姓名....在標籤中,它按預期顯示爲粗體。
我有一個方法:
/// <summary>
/// Creates and shows all session notes in a text format.
/// </summary>
protected void ShowAllSessionNotes()
{
var allNotes = new StringBuilder();
string splitStr = "";
string[] newStr = null;
foreach (var noteItem in SessionNotes())
{
allNotes.Append("<b>" + noteItem.DmSessionNoteType + " - </b>");
allNotes.Append("<b>" + noteItem.DmCommunicationType + " - </b>");
allNotes.Append("<b>" + noteItem.DmContactType + " - </b>");
allNotes.Append(noteItem.AddDateTime + " (CST)");
if (ShowDuration)
{
allNotes.AppendFormat(" - <b>Duration:</b> {0} - <b>Electronically signed by: </b> {1}",
FormatDuration(noteItem.Duration), noteItem.CCName);
}
if (noteItem.Note.Contains('|'))
{
splitStr = noteItem.Note;
newStr = splitStr.Split('|');
noteItem.Note = String.Join("<br/>", newStr);
}
if (noteItem.Note.Contains(':') && noteItem.Note.StartsWith("Electronically"))
{
splitStr = noteItem.Note;
string bldStr = splitStr.Split(':')[0];
}
allNotes.Append("<br />");
allNotes.Append(noteItem.Note);
allNotes.Append("<br /><br />");
}
lblShowAllSessionNotes.Text = allNotes.ToString();
lblShowAllSessionNotes.Visible = true;
}
和另一....
/// <summary>
/// Helper function that populates a session note entity.
/// </summary>
/// <param name="item">The GridEditableItem to pull data from.</param>
/// <param name="sessionNote">Existing PatientSessionNote entity.</param>
/// <returns>Returns a populated PatientSessionNote entity.</returns>
private PatientSessionNote PopulatePatientSessionNote(GridEditableItem item, ref List<string> errors)
{
var id = item.ItemIndex != -1 ? Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"]) : 0;
var rcb = item.FindControl("radCmbNoteType") as RadComboBox;
var rcbCC = item.FindControl("radCmbCommunicationType") as RadComboBox;
var rcbC = item.FindControl("radCmbContactType") as RadComboBox;
var rtb = item.FindControl("rtbNote") as RadTextBox;
string userSign = "Electronically signed by: ";
var appendDate = DateTime.Now;
var appendUser = User.Identity.Name;
var appendName = new MasterBLL().getUserName(appendUser);
var origSessNote = item.FindControl("HideOriginalSessionNote") as HiddenField;
string sessionNoteSent = "";
if (origSessNote.Value == "".Trim() || origSessNote == null)
{
sessionNoteSent = rtb.Text;
}
else
{
sessionNoteSent = origSessNote.Value + " | " + Environment.NewLine + userSign + appendName + " " + appendDate.ToString() + " | " + Environment.NewLine + rtb.Text;
}
var sessionNote = new PatientSessionNote
{
Id = id,
PatientId = _patientId,
DeleteReason = string.Empty,
IsDeleted = false,
LastUpdateDateTime = DateTime.Now,
LastUpdateUserName = CurrentUserId,
CommunicationTypeId = Convert.ToInt32(rcbCC.SelectedValue),
ContactTypeId = Convert.ToInt32(rcbC.SelectedValue),
SessionNoteTypeId = Convert.ToInt32(rcb.SelectedValue),
Note = Server.HtmlDecode(sessionNoteSent)
};
if (id == 0)
{
sessionNote.AddDateTime = DateTime.Now;
sessionNote.AddUserName = CurrentUserId;
}
if (ShowDuration)
{
var rdpSessionDate = item.FindControl("rdpSessionDate") as RadDatePicker;
var txtSessionStartTime = item.FindControl("txtSessionStartTime") as TextBox;
var txtSessionEndTime = item.FindControl("txtSessionEndTime") as TextBox;
//Set any existing values to NULL (for UPDATEs) so that validation doesn't allow incorrect inputs because of pre-existing old values
//This values will be redefined thru the standard INSERT practices
sessionNote.SessionStart = null;
sessionNote.SessionEnd = null;
sessionNote.Duration = 0;
if (rdpSessionDate != null && txtSessionStartTime != null && txtSessionEndTime != null)
{
var regexDate = Regex.Match(rdpSessionDate.DbSelectedDate.ToString(), @"\d{1,2}/\d{1,2}/\d{4}",
RegexOptions.Singleline);
if (regexDate.Success)
{
var startTime = Regex.Match(txtSessionStartTime.Text,
@"(?i)(?<Hours>\d{1,2}):(?<Minutes>\d{2})(?<Meridian>am|pm)", RegexOptions.Singleline);
var endTime = Regex.Match(txtSessionEndTime.Text,
@"(?i)(?<Hours>\d{1,2}):(?<Minutes>\d{2})(?<Meridian>am|pm)", RegexOptions.Singleline);
if (startTime.Success && endTime.Success)
{
//SessionStart & SessionEnd Dates
DateTime varDate;
if (DateTime.TryParse(rdpSessionDate.DbSelectedDate.ToString(), out varDate))
{
var startHours = int.Parse(startTime.Groups["Hours"].Value)%12;
var endHours = int.Parse(endTime.Groups["Hours"].Value)%12;
var startMinutes = int.Parse(startTime.Groups["Minutes"].Value);
var endMinutes = int.Parse(endTime.Groups["Minutes"].Value);
var isStartAM = Regex.IsMatch(startTime.Groups["Meridian"].Value.ToLower(), "am");
var isEndAM = Regex.IsMatch(endTime.Groups["Meridian"].Value.ToLower(), "am");
if (varDate != DateTime.MinValue)
{
var startDate = new DateTime(varDate.Year, varDate.Month, varDate.Day,
((isStartAM) ? startHours : (startHours + 12)), startMinutes, 0);
var endDate = new DateTime(varDate.Year, varDate.Month, varDate.Day,
((isEndAM) ? endHours : (endHours + 12)), endMinutes, 0);
var span = endDate.Subtract(startDate);
sessionNote.SessionStart = startDate;
if (span.TotalMinutes > 0)
//Only log if the amount of minutes is a positive number (integer)
{
sessionNote.SessionEnd = endDate;
sessionNote.Duration = (int) span.TotalMinutes;
}
else
{
errors.Add(@"The start time is greater than the end time");
errors.Add(@"Date chosen: " + rdpSessionDate.DbSelectedDate);
errors.Add(@"Start date time: " + startDate);
errors.Add(@"End date time: " + endDate);
errors.Add(@"Total minutes: " + span.TotalMinutes);
}
}
else
{
errors.Add(@"Invalid date format: " + rdpSessionDate.DbSelectedDate);
}
}
else
{
errors.Add(@"Invalid date format: " + rdpSessionDate.DbSelectedDate);
}
}
else
{
if (!startTime.Success)
{
errors.Add(@"Invalid start time format: " + txtSessionStartTime.Text);
}
if (!endTime.Success)
{
errors.Add(@"Invalid end time format: " + txtSessionEndTime.Text);
}
}
}
else
{
errors.Add(@"Invalid date format: " + rdpSessionDate.DbSelectedDate);
}
}
else
{
if (rdpSessionDate == null)
{
errors.Add(@"RadDatePicker ControlID ""rdpSessionDate"" could not be found");
}
if (txtSessionStartTime == null)
{
errors.Add(@"TextBox ControlID ""txtSessionStartTime"" could not be found");
}
if (txtSessionEndTime == null)
{
errors.Add(@"TextBox ControlID ""txtSessionEndTime"" could not be found");
}
}
}
if (errors.Count > 0)
{
errors.Add("Server date: " + DateTime.Today);
}
return sessionNote;
}
如果我把在第二種方法PopulatePatientSessionNote大膽的標籤< B>(...)的字符串用戶簽名然後它適用於標籤,但不適用於網格。我感謝幫助!