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

[Solved] Get GridDataItem from EditIndexes ??

2 Answers 278 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neal
Top achievements
Rank 1
Neal asked on 06 Apr 2009, 09:28 AM
Hi all,

Getting the grid dataitem from RadGrid.UpdateCommandName is simple enough
(e.CommandName = Telerik.Web.UI.RadGrid.UpdateCommandName) but

As the Grid goes into Edit Mode, (not update mode) I need to retrieve the GridDataItem  ( so I can set my Concurrency cache, and "Lock" the record from editing by other users). BUT this is null at Edit entry point (fine at update)
Docs/Help leads me to believe I must use  .EditIndexes[0]  as opposed to ).EditItems[0]

IS this correct? if so How please.

i.e. 

if (e.CommandName == Telerik.Web.UI.

RadGrid.EditCommandName)
{

 

     dataItem = ((Telerik.Web.UI.

GridDataItem)((Telerik.Web.UI.RadGrid)source).EditItems[0];
//Code to retrieve the name of the DatKeys..
//Code to Retrieve their Values

 

}
I then use a HT to retrieve the other Values I require. 


1) How do I retrieve the dataitem as it enters Edit Mode?
and on Cancel, or& Post Update  I then release the Edited Item from the cache, is this (CancelCommand the same, or do I use some other mechanism to determine which DataItem/Recid to release from my Concurrency Cache.

TIA
Neal
I do this from an inherited overridden System.Web.UI.Page, so i only need to do it once.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Apr 2009, 10:49 AM
Hello Neal,

You cannot access the grid item when its in EditMode, in the EditCommand event  but rather you can access the item in the ItemDataBound event of the grid as shown below:
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)    
    {     
       if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))  
        {  
            GridEditableItem editItem = (GridEditableItem)e.Item;  
            string strtxt = editItem.GetDataKeyValue("ContactName").ToString();  
        }  
    }  

Thanks
Princy.
0
Neal
Top achievements
Rank 1
answered on 06 Apr 2009, 11:04 AM
Hi Princy,

Yup!,.. Went back on actual Code behind in my forms , realised i had access to the GriDEditable Items in the 

event    grid.ItemCommand +=

new Telerik.Web.UI.GridCommandEventHandler( grid_ItemCommand2);
 i had created in the class

 

(Lost focus there, thanks though...can always count on you guys)

and ....thus the following

 

switch (e.CommandName)

 

{

 

case Telerik.Web.UI.RadGrid.EditCommandName:

 

{

 

 

if (!PagePrivilege.EditData)

 

{

disallowAction(

"Not allowed to Edit any Data");

 

e.Canceled =

true;

 

}

Telerik.Web.UI.

GridEditableItem geItem = e.Item as Telerik.Web.UI.GridEditableItem;

 

 

string RecId = "0";

 

 

string RecType = ""; //(Contacts, Plans, SubPlans, Risk, RiskCategory, Tasks, RolePlayers, LocArea, LocMap, Docs)

 

 

//from httable or above case statement.

 

 

if (geItem != null)

 

{

 

//Get name of Id Key

 

 

string RecIdName = (geItem.OwnerTableView.DataKeyNames[0]);

 

 

//Get value of Id Key(by name)

 

RecId = (geItem.OwnerTableView.DataKeyValues[geItem.ItemIndex][RecIdName].ToString()).Trim();

geItem.ExtractValues(htValues);

}

 

goto extractEditItems;

 

}

..
..

 

extractEditItems:

{

 

StringBuilder sbDescr = new StringBuilder();

 

sbDescr.Append(e.CommandName);

sbDescr.Append(

"|");

 

 

foreach (object value in htValues.Values)

 

{

 

if (value != null)

 

{

sbDescr.Append(value.ToString());

sbDescr.Append(

"|");

 

}

}

 

 

string ActionDescr = sbDescr.ToString();

 

 

string Form = this.Logger.getLowestPath(HttpContext.Current.Request.RawUrl.ToString());

 

 

break;

 

 

 

 

 

 

 

}

Tags
Grid
Asked by
Neal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Neal
Top achievements
Rank 1
Share this question
or