This is a migrated thread and some comments may be shown as answers.

How to make an empty string default to today's date

1 Answer 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 10 Jul 2008, 11:56 AM
Hi,

I am connecting to an XML datasource which is an XML file.  I have a date field that either has a date or a blank value.  Is the date value is blank, then I need it to contain today's date.  Please can some one help me here please.  Here is my code:

<radG:GridTemplateColumn
   HeaderText="Date Of Deposit"
   UniqueName="DateOfDeposit">
   <ItemTemplate>
      <asp:Label ID="lblDateOfDeposit" runat="server" Text='<%# Eval("DateOfDeposit") %>'></asp:Label>
   </ItemTemplate>
   <EditItemTemplate>
      <radCln:RadDatePicker
         ID="rdpDateOfDeposit"
         DbSelectedDate='<%# DataBinder.Eval(Container.DataItem, "DateOfDeposit") %>'
         runat="server">
         <DatePopupButton
           HoverImageUrl="~/RadControls/Calendar/Skins/Default/Img/datePickerPopupHover.gif"
           ImageUrl="~/RadControls/Calendar/Skins/Default/Img/datePickerPopup.gif" />
      </radCln:RadDatePicker>
   </EditItemTemplate>
</radG:GridTemplateColumn>

Thanks
Brendan

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 11 Jul 2008, 08:44 AM
Hello Brendan,

Please try the following code in the ItemDataBound event:

void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        if(item["DateOfDeposit"].Text == ""
        { 
            item["DateOfDeposit"].Text = DateTime.Today.ToString(); 
        } 
    } 

The above code gets the data cell "DateOfDeposit" for every data row and checks if it is an empty string. If positive, the cell is assigned the today's date.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or