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

Inserting New Records

2 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deepa Balasundaram
Top achievements
Rank 1
Deepa Balasundaram asked on 13 Aug 2010, 11:35 PM

I am using a RadGridView in my application. It is connected to a binding datasoure. I am using the following code to insert new records. I have two database fields called createdon and createdby. I have to insert values to those two fields whenever I insert a new record. How can I achieve that?

 

this

 

.Validate();

 

 

this.substationBindingSource.EndEdit();

 

 

this.db.SubmitChanges();

 

2 Answers, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
answered on 16 Aug 2010, 06:27 PM

I think you should be able to bring those 2 columns into your Grid(Change your sql to bring those 2 columns) then hide them from the user....

RadGridView1.Columns("CreatedBy").IsVisible = False

Then when a new row is created assign those values:

 

Private Sub RadGridView1_CreateRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCreateRowEventArgs) Handles RadGridView1.CreateRow

 

e.RowInfo.Cells("CreatedBy").Value = "SomePainUser"

End Sub

 

then once you call your submitchanges it should automatically update your underlying database. I have never tried this exact code but it looks like it should work...haha  Hope it helps.

Eric

0
Stefan
Telerik team
answered on 19 Aug 2010, 10:02 AM
Hello,

Thank you for writing. 

I can confirm that Eric's suggestion is the best way to achieve this scenario. 

If you encounter any difficulties implementing it, do not hesitate to contact us.
 
All the best,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Deepa Balasundaram
Top achievements
Rank 1
Answers by
Eric
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or