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

Current Date

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom Edward
Top achievements
Rank 1
Tom Edward asked on 06 Apr 2010, 03:09 PM
Hello,

Newbie here working with the radgrid.
I have a grid on my page and there are 4 bound fields on it. I am using a sqldatasource to connect to the database.
One of the fields is a Datetime field. When inserting a record I want it to default to the current date.
I saw a property called defaultinsertvalue. I tried using <%=Now()%> or <%=Today()%> on this field but I keep getting an error about the value not being able to be converted to system.datetime.
I am using vb by the way,
Can someone guide me in the right direction to get this field autopopulated with the current date and time?

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Apr 2010, 03:31 PM

Hi,

You can set the default value from code hbehind as shown below.

C#:

 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditFormInsertItem)  
        {  
            GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;  
            TextBox textBox = (TextBox)item["ColumnUniqueName"].Controls[0];  
            textBox.Text = DateTime.Now.Date.ToString();            
        }   
    } 

-Shinu.

0
Tom Edward
Top achievements
Rank 1
answered on 06 Apr 2010, 04:11 PM
Hello Shinu,

Thanks for the reply.
Tags
Grid
Asked by
Tom Edward
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tom Edward
Top achievements
Rank 1
Share this question
or