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

Grid Edit Popup - Set UpdateBy UpdateDate Values

6 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mick Suskovich
Top achievements
Rank 1
Mick Suskovich asked on 10 Jul 2009, 01:38 PM

I have a Rad Grid with 
    <MasterTableView EditMode="PopUp"

 

 

 

    <EditFormSettings EditFormType="Template" CaptionFormatString="Entity Properties..." PopUpSettings-Modal="true" >

 

 

 


Using an Object DataSource

 

 

<asp:ObjectDataSource ID="EntityObjectDataSource" runat="server"

 

 

DataObjectTypeName="Namespace.Entities.Enity"

 

 

DeleteMethod="Delete" InsertMethod="Insert" SelectMethod="GetAll"

 

 

TypeName="Namespace.BusinessServices.EntityServices.EntityController"

 

 

UpdateMethod="Update" OldValuesParameterFormatString="original_{0}">

 

 

 

</asp:ObjectDataSource>

 

 

 

I used netTiers to gen service/Entity/ and data access - I have an abstraction layer (controllers) wrapping the net tiers services.

Amongst the controls, I have two text boxes UpdateByTextBox and UpdateDateText Box,
I would like to set these values once the user clicks the 'Save' command button.

(I was able to figure out how to set my CreateByTextBox and CreateDateTextBox by using the following
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

{

 

    if

 

(e.CommandName == RadGrid.InitInsertCommandName)

 

    {

 

        //cancel the default operation

 

        e.Canceled =

true;

 

 

        //Prepare an IDictionary with the predefined values

 

        System.Collections.Specialized.

ListDictionary newValues = new System.Collections.Specialized.ListDictionary() ;

 

 

        //set default value(s)        

 

        newValues[

"CreateBy"] = m_CurrentUserIdentityName; // initialized in page constructor

 

        newValues[

"CreateDate"] = DateTime.Now.ToString();

 

 

        //Insert the item and rebind

 

 

 

        e.Item.OwnerTableView.InsertItem(newValues);

 

    }

Any suggestions/questions or help is greatly appreciated...

6 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 13 Jul 2009, 02:54 PM
Hello Mick,

Similarly with the InitInsert command, when the Save button is pressed in RadGrid's edit form, the ItemCommand event is fired with command name PerformInsert. This is the place where you can reference your custom controls and their values:

void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.PerformInsertCommandName) 
    { 
        GridEditFormInsertItem item = e.Item as GridEditFormInsertItem; 
        //item.FindControl() can be used to retrieve control by ID 
    } 


Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mick Suskovich
Top achievements
Rank 1
answered on 13 Jul 2009, 04:12 PM
Thank you for you reply - it lead me to where I needed to be --> here is a sample of my functioning code - for adding the audit user during and edit/update operation...

if (e.CommandName == RadGrid.UpdateCommandName)  
            {  
 
                GridEditFormItem _GridEditFormItem = e.Item as GridEditFormItem;  
 
                TextBox _TextBox =  _GridEditFormItem.FindControl("UpdateByTextBox") as TextBox;  
                  
                if (_TextBox != null)  
                    _TextBox.Text = m_CurrentUserIdentityName;  
 
            } 
0
Emad
Top achievements
Rank 1
answered on 22 Dec 2011, 12:37 PM
Hi,

I have the same problem, I tried Mick code but it gives me error "NullReference unhanded by user code"
Note "CREATED_BY" is GridBoundColumn because i use automatic insert/update/delete operations.

please advice...




C#
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
GridEditFormItem item = e.Item as GridEditFormItem;
TextBox tBox = new TextBox();
tBox = item.FindControl("CREATED_BY") as TextBox;
if (tBox != null)
tBox.Text = "emad"
  
}

Thanks
Emad
0
Veli
Telerik team
answered on 22 Dec 2011, 01:01 PM
Try the following code instead:

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        GridEditFormItem item = e.Item as GridEditFormItem;
        TextBox tBox = item["CREATED_BY"].Controls[0] as TextBox;
        if (tBox != null)
            tBox.Text = "emad";
    }  
}

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Emad
Top achievements
Rank 1
answered on 23 Dec 2011, 04:52 PM
Hello Veli,

unfortunately, it's not working..

TextBox tBox = item["CREATED_BY"].Controls[0] as TextBox;
this line raise error null reference exception.
item name is correct.


Please advice.

Thanks,
Emad
0
Emad
Top achievements
Rank 1
answered on 25 Dec 2011, 07:43 AM
Thanks, I found the solution

add the below code and onUdating data source call this code


C#
protected void EntityDataSource1_Updating(object sender, EntityDataSourceChangingEventArgs e) 
    
       Organization org = (Organization)e.Entity; 
       org.UpdateBy = "[UserID]"
    }


Regards,
Emad
Tags
Grid
Asked by
Mick Suskovich
Top achievements
Rank 1
Answers by
Veli
Telerik team
Mick Suskovich
Top achievements
Rank 1
Emad
Top achievements
Rank 1
Share this question
or