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

How to automatically insert a column value

4 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stavros
Top achievements
Rank 1
Stavros asked on 24 Nov 2008, 10:22 AM

I have a grid and I am using an insert command to enter records to an underneath table.

How can I automatically insert a column value (for example user_id) to a column?

I have made this column read only so that the user enters some values but he doesn't see that user_id column.

I get the user_id using the following code :

 

string UserID; //globally declare the UserId   
    protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        MembershipUser myObject = Membership.GetUser();  
        UserID = myObject.ProviderUserKey.ToString();  
    } 

4 Answers, 1 is accepted

Sort by
0
Stavros
Top achievements
Rank 1
answered on 26 Nov 2008, 12:25 AM
difficult? :)
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2008, 08:31 AM
 Hi stavros,

Telerik RadGrid can extract values even from columns that are set as read-only, if the column's property ForceExtractValue is set to:

"InBrowseMode" - when deleting records
"InEditMode" - when inserting/updating records
"Always" - for all modes

The default value for this property is "None", i.e. the extraction of the default values will not be performed only for read-only columns.

Thanks,
Shinu.
0
Sebastian
Telerik team
answered on 28 Nov 2008, 08:41 AM
Hi guys,

Additionally, to provide default value for the user_id column on item insertion, consider marking this column in the grid source as auto-incremented or of type GUID to ensure that unique value will be generated for each new entry.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Simon
Top achievements
Rank 1
answered on 28 Nov 2008, 09:58 AM
Hi Sebastian

My reading of Stavros' question might be a little different to yours.

Your suggestion of an autoincrement or GUID would work well where an unique ID number for the row was required, but I read that Stavros was looking to put a particular user's ID number in the new row.

I might be putting my own spin on this, but I have a situation where I'd like to tag each new row added to a table with the ID number of the user who inserted the record. I think Stavros might have been asking the same thing.

- Simon
Tags
Grid
Asked by
Stavros
Top achievements
Rank 1
Answers by
Stavros
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Sebastian
Telerik team
Simon
Top achievements
Rank 1
Share this question
or