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

Change a cell value before database update

2 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 01 Oct 2013, 08:21 PM
Hi, 

I have a radgrid holding customer notes with a column called UserUpdated.  The UserUpdated column is the last user to have updated the note in the row.  It is a template column like this:

<telerik:GridTemplateColumn DataField="UserEdited"    FilterControlAltText="Filter UserEdited column"   HeaderText="UserEdited" SortExpression="UserEdited" UniqueName="UserEdited">
    <EditItemTemplate>
                                    <asp:Label ID="UserEditedLabel2" runat="server" Text='<%# Bind("UserEdited") %>'></asp:Label>
    </EditItemTemplate>
    <ItemTemplate>
                                    <asp:Label ID="UserEditedLabel" runat="server" Text='<%# Eval("UserEdited") %>'></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>



When the person hits the edit button on  that row, I want the row to continue continue to show that value while they are editing.  That way, if they cancel their edit, the grid will not have to be rebound and that cell value will not have changed.

But when they hit the update button to commit their changes, I want to intercept it and change the UerEditedLabel2.Text value to the current user's username before the commit.

I have tried probably 10 ways to do this with no luck.  

Any help would be appreciated.  Thanks.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Oct 2013, 10:13 AM
Hi Jonathan,

Please try the following code snippet to achieve your required scenario.

ASPX:
<telerik:GridTemplateColumn DataField="OrderName" HeaderText="OrderName" UniqueName="OrderName">
    <EditItemTemplate>
      <asp:TextBox ID="Textbox1" runat="server" Text='<%# Eval("OrderName") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderName") %>'></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       if (e.Item is GridEditableItem)
       {
           GridEditableItem edit = (GridEditableItem)e.Item;
           TextBox txt = (TextBox)edit.FindControl("Textbox1"); //access the TextBox inside the TemplateColumn currently being edited
           txt.Text = "Current user's name"; //Set it to your required value
       }
   }

Thanks,
Shinu
0
Jonathan
Top achievements
Rank 1
answered on 03 Oct 2013, 05:49 PM
That worked very well.  Thanks!
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jonathan
Top achievements
Rank 1
Share this question
or