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

disable edit command for specific rows

2 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Douglas Hale
Top achievements
Rank 1
Douglas Hale asked on 12 Jul 2010, 04:55 AM
I want to disable the edit command for rows that have a specific value in say the third column.  The code below seems to disable the whole edit column if the "if statement" is met jsut once.

Thanks
Doug

protected void teamGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
  
                string firstName = dataItem["Firstname"].Text;
                string lastName = dataItem["Lastname"].Text;
  
                LinkButton button = dataItem["DeleteColumn"].Controls[0] as LinkButton;
                button.Attributes["onclick"] = "return confirm('Are you sure you want to deactivate " + firstName + " " + lastName + "?')";
  
  
                if (dataItem["EndDate"].Text != "")
                {
                    LinkButton linkButton = (LinkButton)dataItem["EditCommandColumn"].Controls[0];
                    linkButton.Enabled = false;
  
                    dataItem["EndDate"].Font.Strikeout = true;
                }
            }
        }
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Jul 2010, 08:28 AM
Hello Douglas,

Check for " " instead of  empty value (ie; "" )  in your if statement.

C#:
if (dataItem["EndDate"].Text != " ")
  {
    LinkButton linkButton = (LinkButton)dataItem["EditCommandColumn"].Controls[0];
    linkButton.Enabled = false;
    dataItem["EndDate"].Font.Strikeout = true;
   }

Thanks,
Princy.
0
Douglas Hale
Top achievements
Rank 1
answered on 12 Jul 2010, 12:57 PM
That's incredible!  I'm not sure why that works but it does.  Thank you very much!
Tags
Grid
Asked by
Douglas Hale
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Douglas Hale
Top achievements
Rank 1
Share this question
or