[英]How to find label value (database coloumn) of repeater and change text on repeater_ItemDataBound event
这是我在中继器的标签中显示的数据库值“ 2012/04/24”,我必须在中继器的标签中显示这样的数据库值(2012年4月12日)。 在repeater_ItemDataBound事件上我该怎么办。
<td class="csstablelisttd">
<asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%#Eval("Patients_Birth_Date")%>'></asp:Label>td>
protected void repeaterPatientList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Label lblbirthDate = (Label)e.Item.FindControl("lblPatientsBirthDate");
}
要将日期格式化为特定格式,可以这样做:
<asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%# Eval("Patients_Birth_Date", "{0:dd-MMM-yyyy}")%>' </asp:Label>
您需要在repeater_ItemDataBound事件上更改文本。
希望这会帮助你。
尝试这个:
protected void repeaterPatientList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Label lblbirthDate = (Label)e.Item.FindControl("lblPatientsBirthDate");
if(lblbirthDate!= null)
{
DateTime d = DateTime.Parse(lblbirthDate.Text);
lblbirthDate.Text = d.ToString("dd-MMM-yyyy");
}
}
如果日期转换导致错误,请遵循DateTime.ParseExact方法和自定义日期和时间格式字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.