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

ItemInserted nor InsertCommand firing

1 Answer 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Magni
Top achievements
Rank 1
Magni asked on 21 Jul 2011, 02:00 AM
I have dynamically added RadGrid on a RadWindow using a ITemplate. I cant get ItemInsert event to fire.
I image something with the initialization is not correct i.e. base.OnInIt(e);. Could it be the problem ?

Here is my code:

void ITemplate.InstantiateIn(Control owner)
        {
            RadGrid rg = new RadGrid();
            rg.ID = "UserManagementTemplateGrid";
            rg.Width = 600;
            rg.Skin = "Default";
            rg.NeedDataSource += new GridNeedDataSourceEventHandler(rg_NeedDataSource);
           
            rg.RegisterWithScriptManager = true;
            rg.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
            rg.ShowHeader = true;
            rg.AutoGenerateColumns = false;
            rg.AutoGenerateEditColumn = false;
            rg.AllowAutomaticInserts = true;
            rg.AllowAutomaticUpdates = true;
            rg.AllowAutomaticDeletes = true;
            rg.AllowSorting = true;
            rg.PageSize = 10;
            rg.AllowPaging = true;

            rg.MasterTableView.Name = "MasterTableView";
            rg.MasterTableView.EditMode = GridEditMode.InPlace;
            rg.MasterTableView.DataKeyNames = new string[] { "ID", "UserName", "Password", "Email", "UserTypeID", "Active" };

            rg.MasterTableView.Columns.Add(AddBoundColumn("ID", "ID", false));
            rg.MasterTableView.Columns.Add(AddBoundColumn("UserName", "User name", true));
            rg.MasterTableView.Columns.Add(AddBoundColumn("Password", "Password", true));
            rg.MasterTableView.Columns.Add(AddBoundColumn("Email", "Email", true));
            rg.MasterTableView.Columns.Add(
                AddTemplateDropDownListColumn("UserTypeID", ListTypes.UserType, "Type", "UserTypeName", "UserTypeID")
            );
            rg.MasterTableView.Columns.Add(
                AddTemplateDropDownListColumn("Active", ListTypes.Active, "Active", "Active", "Active")
            );

            GridEditCommandColumn gecc = new GridEditCommandColumn();
            gecc.UniqueName = "EditCommandColumn";
            gecc.ButtonType = GridButtonColumnType.ImageButton;
            gecc.EditText = "Edit";
            gecc.UpdateText = "Save";
            gecc.CancelText = "Cancel";
            gecc.InsertText = "Add new";
            rg.MasterTableView.Columns.Add(gecc);

            rg.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
            rg.MasterTableView.CommandItemSettings.AddNewRecordText = "Add new";
           
            //grid events
            rg.ItemInserted += new GridInsertedEventHandler(rg_ItemInserted);
            rg.ItemUpdated += new GridUpdatedEventHandler(rg_ItemUpdated);
            rg.ItemDeleted += new GridDeletedEventHandler(rg_ItemDeleted);
            rg.InsertCommand += new GridCommandEventHandler(rg_InsertCommand);

            //Adding RadGrid to Control
            owner.Controls.Add(rg);
        }

void rg_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid rg = (RadGrid)sender;
            rg.DataSource = User.GetUsers;
        }

void rg_ItemInserted(object sender, GridCommandEventArgs e)
        {
            throw new NotImplementedException();
        }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jul 2011, 04:59 AM
Hello Magni,

Check the following help documentation which explains how to add a RadGrid dynamically. Hope this helps.
Programmatic Creation.

Thanks,
Princy.
Tags
Grid
Asked by
Magni
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or