How to automatically insert a column value

5 posts, 0 answers
  1. Stavros
    Stavros avatar
    89 posts
    Member since:
    Sep 2008

    Posted 24 Nov 2008 Link to this post

    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();  
        } 
  2. Stavros
    Stavros avatar
    89 posts
    Member since:
    Sep 2008

    Posted 25 Nov 2008 Link to this post

    difficult? :)
  3. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Nov 2008 Link to this post

     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.
  4. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 28 Nov 2008 Link to this post

    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.
  5. Simon
    Simon avatar
    30 posts
    Member since:
    Jun 2007

    Posted 28 Nov 2008 Link to this post

    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
Back to Top