0

I am databinding a repeater some text and a datetime(Respond By).

<asp:Repeater ID="rptList" OnItemDataBound="repeaterDatabound" runat="server">
     <HeaderTemplate>
     </HeaderTemplate>
     <ItemTemplate>
         <tr>
              <td>
                  <b>Respond By</b>
              </td>
              <td>
                  <%#Eval("RespondBy")%>
              </td>
          </tr>

Here I want to change the datatime before I display it on the screen, I want to do a rowdatabound similar to the one below. How can I do that for a repeater. Or is there anyother way of adding value(3Hrs) to Respond by dateTime before displaying it to users.

   protected void repeaterDatabound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DateTime.TryParse(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "RespondBy")), out Respond);
        }
    }

I cant add 3hrs in the client side, the no of hours I have to add is different for each users,

Mark
  • 2,720
  • 15
  • 56
  • 87
  • What kind of manipulation are you trying to do? Is it nothing that could be accomplished with formatting or an addtional column in the datasource? – James Johnson Nov 18 '11 at 15:55

2 Answers2

0

You can either do following in aspx file.

 ((DateTime)Eval("RespondBy")).AddHours(3)

Or add a label/literal in aspx instead of <%#Eval("RespondBy")%> and use it in ItemDataBound

Junaid
  • 1,708
  • 16
  • 25
0

You could either change your <%#Eval("RespondBy)%> to some server control, a <asp:Literal> for example, then update the value of this in your ItemDataBound method.

Or you could use some inline code

<%#((DateTime) Eval("RespondBy")).AddHours(3).ToString("dd MMMM yyyy")%>

Or you could produce a public function which you can then reuse in the future.

public static string RespondByDate(DateTime theDate){
    return theDate.AddHours(3).ToString("dd MMMM yyyy");
}
Tim B James
  • 20,084
  • 4
  • 73
  • 103