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

Use default values in grid edit/insert

6 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 Jun 2010, 02:15 PM
Hi,
In a radgrid with automatic edit/insert/delete, is there a way to either automatically enter default values (like the current date and time) into a text box when the user clicks edit or add new, or a way to get and modify the entry boxes' content or the compiled SQL statement before it is executed after the user clicks update?  I want to use the current date and time for date entries in some SQL databases.  I guess I could probably just make the date fields read only and call a separate SQL edit command inserting the dates, but would rather not.

Thanks,
Chris

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jun 2010, 02:40 PM
Hello Chris,

You can access the control in ItemDataBound event and set the value to required as shown in the forum.

Let me know if you need further help,
Shinu.
0
Chris
Top achievements
Rank 1
answered on 02 Jun 2010, 03:10 PM
That looks like it will work great, thanks.  But I'm using vb and am having trouble with "ColumnUniqueName" and getting the control and casting it to a textbox.  Any help on how to change that line to vb?

Thanks again,
Chris

0
Princy
Top achievements
Rank 2
answered on 03 Jun 2010, 11:40 AM
Hello Chris,

You can easily convert the C# code to VB equivalent and vice versa, using the following online .net code converter.
Code Converter

And here is the code in VB:
 
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) 
     If e.Item.OwnerTableView.IsItemInserted AndAlso TypeOf e.Item Is GridEditFormInsertItem Then 
        Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem) 
        Dim textBox As TextBox = DirectCast(item("ColumnUniqueName").Controls(0), TextBox) 
        textBox.Text = "My Text" 
     End If 
  End Sub 


Thanks,
Princy.







0
Chris
Top achievements
Rank 1
answered on 03 Jun 2010, 12:53 PM
Hi Princy,

I was wondering if there was a converter like that, but never bothered to look for one, so thank you.

This code works for when adding a new item, but I would also like to do this or something similar for when the user clicks to edit a row.  I've tried a little bit myself, but my understanding of all this isn't quite good enough yet.  Any help with this would be greatly appreciated.

Also, how would I change this to work for inPlace inserting/editing?

Thanks,
Chris

P.S.
The Code Converter link doesn't work.

0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Jun 2010, 01:07 PM
Hello Chris,

Check out the following code snippet to access the control in InPlace edit/insert.

VB.Net:

Protected
 Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
        If e.Item.OwnerTableView.IsItemInserted AndAlso TypeOf e.Item Is GridDataInsertItem Then 
            Dim item1 As GridDataInsertItem = DirectCast(e.Item, GridDataInsertItem) 
            Dim textBox As TextBox = DirectCast(item1("ColumnUniqueName").Controls(0), TextBox) 
            textBox.Text = "My Text insert" 
        Else 
            Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
            Dim textBox As TextBox = DirectCast(item("ColumnUniqueName").Controls(0), TextBox) 
            textBox.Text = "My Text edit" 
        End If 
    End If 
End Sub 

And here is the converter link:
http://converter.telerik.com



Thanks,
Princy.


0
Chris
Top achievements
Rank 1
answered on 04 Jun 2010, 01:38 PM
Thanks, that's great!

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or