简体   繁体   English

如何查找转发器的标签值(数据库列)和更改repeater_ItemDataBound事件上的文本

[英]How to find label value (database coloumn) of repeater and change text on repeater_ItemDataBound event

This is my database value "2012/04/24" i dispalyed in label of repeater i have to display database value like this 12-Apr-2012 in label of repeater. 这是我在中继器的标签中显示的数据库值“ 2012/04/24”,我必须在中继器的标签中显示这样的数据库值(2012年4月12日)。 on repeater_ItemDataBound event How can i do it. 在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");


    }

For formatting date into a particular format, it could be done by this: 要将日期格式化为特定格式,可以这样做:

<asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%# Eval("Patients_Birth_Date", "{0:dd-MMM-yyyy}")%>' </asp:Label>

You need to change text on repeater_ItemDataBound event. 您需要在repeater_ItemDataBound事件上更改文本。

Hope this will help you. 希望这会帮助你。

Try this: 尝试这个:

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");
        }
    }

If date conversion cause error then follow DateTime.ParseExact Method and the Custom Date and Time Format Strings 如果日期转换导致错误,请遵循DateTime.ParseExact方法自定义日期和时间格式字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM