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

problem displaying an error message

3 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 27 Jul 2011, 06:34 PM
I want to display an error message in the grid if some operation has failed  (update, delete, etc)
Ive followed an example suggested in the forums, but it doesnt work

protected void RadGridImages_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            List<Business.Logic.BusinessObjects.ArtistImage> lst = new List<Business.Logic.BusinessObjects.ArtistImage>();
            int aid = -1;
            bool isOK = int.TryParse(this.HiddenArtistID.Value, out aid);
            if (isOK)
            {
                lst = artistImageManager.Get(aid);
                if (lst != null)
                {
                    this.RadGridImages.DataSource = lst;
                }
                else
                {
                    if (this.RadGridImages.DataSourceID == "")
                    {
                        this.RadGridImages.DataSource = new string[] { };
                    }
                }
            }
            if (!string.IsNullOrEmpty(gridMessage))
            {
                DisplayMessage(gridMessage);
            }
        }
        private void DisplayMessage(string text)
        {
            RadGridImages.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
        }

gridMessage is supplied a value when something fails, I then rebind the grid

there IS a value in gridMessage when the NeedDataSource is fired, but the error message never gets displayed.
Anyone see what Im doing wrong here ?

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 02 Aug 2011, 09:08 AM
Hello Mark,

Possible appraoch for acheiving the required fucntionality is to add an error label in the EditForm in ItemDataBound event to show the message. For example:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode && check)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;
        Label lbl = new Label();
        lbl.ID = "ErrorLabel";
        lbl.Text = "Error";
        lbl.ForeColor = System.Drawing.Color.Red;
        (item.FindControl("CancelButton").Parent).Controls.Add(lbl);
        check = false;
    }
}
 
 
 
protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)
{
    GridEditFormItem item = (GridEditFormItem)e.Item;
    if (e.Exception != null)
    {
        e.KeepInEditMode = true;
        e.ExceptionHandled = true;
        check = true;
 
    }
}


Also note that an easy method to validate data in edit form is using validation control for the controls in edit form. Please take a look at the following demo and see if it helps.
Grid / Flexible Server-side Validation

I hope this helps.

Kind regards,
Maria Ilieva
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
mww
Top achievements
Rank 1
answered on 02 Aug 2011, 09:30 AM
OK thanks for your help, but why wont the other suggested method work ?  this was a solution recommend by the support team

RadGridImages.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));


also, data validation isnt really the issue here, its just a way of trapping any unforeseen problems (like a database update failure)
0
Maria Ilieva
Telerik team
answered on 04 Aug 2011, 03:35 PM
Hello,

I'm not sure where the provided code you are trying to implement is suggested. Actually the proper approach is presented in the following online demo.

Best wishes,
Maria Ilieva
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
mww
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
mww
Top achievements
Rank 1
Share this question
or