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

add controls to auto-generated forms

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 04 Oct 2011, 06:23 PM
I am working with an autogenerated edit form and trying to get controls that have added in code behind to display on the top of the form.  Here is the code that I am trying to get working.

        protected void MyOnItemInserted(object sender, GridInsertedEventArgs e)
        {
            try
            {
                if (e.Exception != null)
                {
                    e.ExceptionHandled = true;
                    e.KeepInInsertMode = true;
                    check = true;
                    throw new AssetManager.Helper.UniqueIndexViolationException("Error:  Item already exists");
                }
            }
            catch (AssetManager.Helper.UniqueIndexViolationException ex)
            {


                if (e.Item is GridEditFormItem && e.Item.IsInEditMode && check)
                {
                    AssetManager.FormException FormException = new AssetManager.FormException();
                    FormException.Message = ex.Message.ToString();
                    GridEditFormItem _form = e.Item as GridEditFormItem;
                    
                    TableCell cell = _form.EditFormCell as TableCell;
                    
                    for (int i = 0; i < cell.Controls.Count; i++)
                    {
                        if (cell.Controls[i].GetType() == FormException.GetType())
                        {
                            //form exception is already there, remove it and display new message
                            cell.Controls.Remove(FormException);
                            cell.Controls.Add(FormException);


                        }
                        else
                            //add form exception control to table cell
                            cell.Controls.Add(FormException);
                    }
                }
            }

            catch (Exception ex)
            {


            }
        }

I can see the control get added to teh cell.Controls collection but the cell text does not update with the message.  Am I missing something that would update the cell on the postback?  I am doing this in the Inserted event.  Can anyone see what I might be missing?

1 Answer, 1 is accepted

Sort by
0
Jeremy
Top achievements
Rank 1
answered on 04 Oct 2011, 07:32 PM
This code will place the label control on the grid behind the pop up edit form

                if (e.Item is GridEditFormItem && e.Item.IsInEditMode && check)
                {
                    GridEditFormItem _form = e.Item as GridEditFormItem;
                    TableCell cell = _form.EditFormCell as TableCell;
                    AssetManager.FormException FormException = new AssetManager.FormException();
                    FormException.Message = ex.Message.ToString();
                    
                    Label xtest = new Label();
                    xtest.ID = "lblVerify";
                    xtest.Text = FormException.Message;
                    cell.Controls.AddAt(0, xtest);

However, I am trying to get it to the top of the edit form to handle sql exceptions.while in edit mode
Tags
Grid
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Jeremy
Top achievements
Rank 1
Share this question
or