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

Grid Form Template Edit Form notification message

2 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ILJIMAE
Top achievements
Rank 1
ILJIMAE asked on 07 Aug 2012, 07:47 AM
Dear Telerik support team,

In the "Grid / Form Template Edit Form" example on this website, in Default.CS.aspx.cs class, there's a code block which runs when the user updates a record as shown below.



protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
{
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
DisplayMessage(true, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " updated");
}
}



The code above displays the notification message "Employee 3 updated"
If I want this notification message to display a message like "Employee Robert King updated"  how do I accomplish this?

I tried to use the code shown below but I don't think the code works correctly because the variable IDNumber gets the value from the field EmployeeID rather than the RadGrid's ItemIndex which starts from 0.

int IDNumber = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"];

string EmployeeName = RadGrid1.MasterTableView.Items[IDNumber]["FirstName"].Text;

DisplayMessage(false, "Employee " + EmployeeName + " updated")

 

Many thanks,

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Aug 2012, 01:37 PM
Hello,

Template Column
TextBox txtFirstName = e.Item.FindControl("txtFirstName") as TextBox;
<telerik:GridTemplateColumn>
                     <EditItemTemplate>
                         <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
                     </EditItemTemplate>
                 </telerik:GridTemplateColumn>

Bound Column

TextBox txtFIrstName = ((e.Item as GridEditableItem)["FirstName"].Controls[0] as TextBox);
<telerik:GridBoundColumn DataField="Name" UniqueName="FirstName" HeaderText="FirstName"></telerik:GridBoundColumn>


Thanks,
Jayesh Goyani
0
ILJIMAE
Top achievements
Rank 1
answered on 08 Aug 2012, 12:50 AM
Thank you for your reply, but I was asking a different question.

I was asking about the Telerik grid example shown on the web page :
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx

When I update a record on the grid, the page displays a message "Employee 1 updated" ABOVE the grid.

But I am trying to find a way to change the displayed message so that it displays like: "Employee Nancy Devolio updated" by modifying the code (RadGrid1_ItemUpdated) in the defaultcs.aspx.cs page.

So, could you please explain how I can accomplish this?

Thank you.




Tags
Grid
Asked by
ILJIMAE
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
ILJIMAE
Top achievements
Rank 1
Share this question
or