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

[Solved] Toggle edit command text/visibility per row?

2 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 29 Jun 2009, 03:31 PM
I've been working at this and can't seem to come up with a way to make it work.

I have a grid that designates specific rows as having errors.  On these rows, and these rows only, I want to display the Edit command to display an edit form template.

Here is my code behind for catching and identifying the bad records.  How can I tie into this to either set my edit command text to "Error..." or "" depending on if I want it to show or not.

[code]
protected void rgridOrders_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                bool _isError = Convert.ToBoolean(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IsError"].ToString());
                if (_isError)
                {
                    GridItem dataItem = e.Item;
                    dataItem.BackColor = System.Drawing.Color.FromArgb(255, 220, 220);
                    dataItem.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
[/code]


2 Answers, 1 is accepted

Sort by
0
Chris T.
Top achievements
Rank 1
answered on 29 Jun 2009, 03:56 PM
in your if(_isError) block, try the following:

((LinkButton)dataItem["<UniqueName of your EditCommandColumn>"].Controls[0]).visible = false;

That's how we're doing it here.  And after looking at it, I'm thinking .Controls[0] might want to be replaced with some sort of FindControl just in case Telerik changes the layout of the EditCommandColumn, but as of the version we have (Q1 2009 SP2), that hasn't happened.

YMMV and all that, hope it helps!

-Chris
0
Carl
Top achievements
Rank 1
answered on 30 Jun 2009, 12:29 PM
Thanks Chris.  I'll have a go at that today.

If I'm not mistaken though, dataItem["<UniqueName of your EditCommandColumn>"] won't be valid.  I seem to remember having to do a dataItem.FindControl("whatever") and that ultimately didn't get me what I was after.

However, I was also not going at is as a (LinkButton) which may be part of my problem.  I kept trying to get it as a GridEditCommand where I could change the EditText property.

I'll let you know how it goes and thanks.
Tags
Grid
Asked by
Carl
Top achievements
Rank 1
Answers by
Chris T.
Top achievements
Rank 1
Carl
Top achievements
Rank 1
Share this question
or