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

OnEditCommand - how to access column values and manipulate UI

3 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 29 Jan 2013, 07:18 PM
hello,

in our RadGrid we use in-row editing. however, i need to make certain editable elements read-only (or disabled), depending on the value in another bound column. for example, if the value of the "Status" read-only GridBoundColumn is "Rejected", then i need to disable editing for the other editable GridCheckBoxColumn and GridDropDownColumn columns we have. 

i think this may be done in the OnEditCommand handler...but I'm not sure what the syntax is. have checked the docs but didn't see it. 

i determined i can use the item.Cells collection to get the Status column's string value, like so:

protected void gridItems_EditCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem editableItem = e.Item as GridEditableItem;
 
    string status = e.Item.Cells[6].Text; //i mapped this out, 6 is the Status column value.
 
    switch (status.ToLower())
    {
        case "rejected":
            //TODO: disable the UI for editing my particular columns here:
 
            // GridCheckBoxColumn
            // GridDropDownColumn
            // GridTemplateColumn
 
            break;
    }
}


...or do i intercept this on the OnCreateColumnEditor="gridItems_CreateColumnEditor" or OnItemDataBound="gridItems_ItemDataBound" events/handlers?

thanks,
matt

3 Answers, 1 is accepted

Sort by
0
matt
Top achievements
Rank 1
answered on 29 Jan 2013, 11:29 PM
ok, if found my solution -- it was not in the OnEditCommand event handler, but rather the ItemDataBound's. like so:

protected void gridItems_ItemDataBound(object source, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item is GridEditableItem)
    {
        //NOTE: if this grid supported inserts, we'd have to test against "e.Item.ItemIndex == -1", since -1 is used by inserts.
 
        GridEditableItem editableItem = e.Item as GridEditableItem;
 
        //get test status status
        string status = ((TextBox)editableItem["Status"].Controls[0]).Text;
 
        switch (status.ToLower())
        {
            case "rejected":
                editableItem["UseInAllocation"].Enabled = false;
                editableItem["UseInToleranceCalculation"].Enabled = false;
                editableItem["AcceptanceStatus"].Enabled = false;                      
                break;
        }
    }
}


...this does the trick!

and heres how to disable/remove the "Update" command GridLinkButton:

http://www.telerik.com/community/forums/aspnet-ajax/grid/itemdatabound---conditionally-disable-command-link-button.aspx
0
Matt
Top achievements
Rank 1
answered on 27 Nov 2017, 05:56 PM

I know this post is old but I'm stuck regardless...

This isn't being called but is in the mark-up:

OnItemDataBound="RadGrid1_ItemDataBound"

And here is the method:

 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if(e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.ItemIndex > -1)
            {
                GridEditableItem gridEditableItem = (GridEditableItem)e.Item;
                ((RadDropDownList)gridEditableItem["UserRoleDesc"].Controls[0]).SelectedValue = gridEditableItem["Wbg_ID"].Text;

                RadDropDownList RDDL_Wbg_ID = (RadDropDownList)gridEditableItem.FindControl("RDDL_Wbg_ID");
                RDDL_Wbg_ID.SelectedValue = gridEditableItem["Wbg_ID"].Text;
                RadDropDownList RDDL_AccessLevel = (RadDropDownList)gridEditableItem.FindControl("RDDL_AccessLevel");
                RDDL_AccessLevel.SelectedValue = gridEditableItem["AccessLevel"].Text;
                RadDropDownList RDDL_ExemptStat = (RadDropDownList)gridEditableItem.FindControl("RDDL_ExemptStat");
                RDDL_ExemptStat.SelectedValue = gridEditableItem["ExemptStat"].Text;
            }
        }

Neither of these methods are working. Even if I put a RadAlert in, nothing happens. I also have AllowMultiRowEdit="true", if that makes a difference.

0
Marin Bratanov
Telerik team
answered on 30 Nov 2017, 02:23 PM

Hi Matt,

Can you confirm that AutoEventWireup="true" in the Page directive?

You can also try attaching the handler in the code behind:

protected void Page_Init(object sender, EventArgs e)
{
    RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
}
 
private void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    //code here
}

The only other reason I can think of is that the grid is bound on the client and so its server events would not fire. 

If neither helps, I suggest you open a ticket and send us a small runnable example that showcases the scenario and the problem.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
matt
Top achievements
Rank 1
Answers by
matt
Top achievements
Rank 1
Matt
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or