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

Access dataitem in GridEditForm/InEditMode

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 22 Jan 2009, 06:01 PM
in my itemdatabound event handler, I want to populate an edited item dropdownlist based on the value of a grid dataitem, the reference to the dataitem (Points) fails like so:

 

 

if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
 
{  
 
GridEditFormItem item = (GridEditFormItem)e.Item;  
 
GridEditableItem eeditedItem = e.Item as GridEditableItem;  
 
DropDownList list = item.FindControl("NumericGrade") as DropDownList;  
 
 
 
 
 
GridDataItem dataItem = e.Item as GridDataItem;  
 
String sPoints = dataitem["Points"].Text;  
int iPoints = Convert.ToInt16(sPoints);  
 
for (int j = 0; j < iPoints + 1; j++)  
 
{  
 
list.Items.Add(j.ToString());  
 
}  
 

I guess I could create a GridTemplateColumn for the Points field and then it would be accessible in GridEditFormItem(?) but I don't really want to through extra fields into the edit form?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jan 2009, 05:46 AM
Hello David,

You can try the following code instead to achieve the required scenario.
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
  { 
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)    
    {    
         GridEditFormItem item = (GridEditFormItem)e.Item;    
         DropDownList list = item.FindControl("NumericGrade") as DropDownList;   
            
         GridDataItem dataItem = (GridDataItem)item.ParentItem; //to access the GridDataItem(parent)  
         int iPoints = Convert.ToInt16(dataItem["Points"].Text);     
         for (int j = 0; j < iPoints + 1; j++)    
           {    
              list.Items.Add(j.ToString());   
           }   
     } 
  } 

Thanks
Princy.
Tags
Grid
Asked by
david
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or