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

DropDownList Commands

1 Answer 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
HSD
Top achievements
Rank 1
HSD asked on 28 Oct 2013, 05:55 PM
I can't figure this out.  I have a RadComboBox inside a GridTemplateColumn with Items for commands.  When a command is selected from the DropDownList it posts back.
protected void gvTransactionsCommandList_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox myBox = (RadComboBox)sender;
            if (myBox != null && !string.IsNullOrEmpty(myBox.SelectedValue.Trim()))
            {
                GridDataItem item = (GridDataItem)myBox.NamingContainer;
                RadGrid grid = (RadPane1.FindControl("gvTransactions") as RadGrid);
                gvTransactions.MasterTableView.Items[item.ItemIndex].Selected = true;
                (grid.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem).FireCommandEvent(myBox.SelectedValue, string.Empty);
            }
        }

This Fires the selected command. Which is processed by this code.

protected void gvTransactions_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "InitInsert":
                    gvTransactions.SetInsertControl("UserControls/TransactionDetails.ascx");
                    break;
                case "RowClick":
                    gvTransactions.SetUpdateControl("UserControls/TransactionDetails.ascx", e);
                    break;
                case "ViewProcess":
                    gvTransactions.SetUpdateControl("UserControls/TransactionDetails.ascx", e);
                    break;
                case "PerformInsert":
                    UserControl userControl = gvTransactions.GetInsertControl(e);
                    break;
                case "PerformUpdate":
                    DataTable dtOld = StoredProcedure.ReturnData("spPeople_AppointmentManager_Get", "@TransactionID", gvTransactions.GetKeyValue(e));
                    UserControl userUpdateControl = gvTransactions.GetUpdateControl(e);
 
                    gvTransactions.CloseUpdateControl(e);
                    break;
                case "PerformDelete":
                    StoredProcedure.RunCommand("spPeople_AppointmentManager_Delete", "@AcademicID", gvTransactions.GetKeyValue(e));
                    gvTransactions.CloseUpdateControl(e);
                    break;
            }
        }

This code is sent here to bind the UserControl appropriate for the selected command.

public static void SetUpdateControl(this RadGrid control, string userControlName, GridCommandEventArgs e)
        {
            control.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
            control.MasterTableView.EditFormSettings.UserControlName = userControlName;
            control.MasterTableView.EditFormSettings.EditColumn.UniqueName = "EditFormControl";
            control.MasterTableView.Items[e.Item.ItemIndex].Edit = true;
            control.MasterTableView.Rebind();
        }

The Error Comes at this line where it states "invalid index".  The e.Item.ItemIndex is -1.
control.MasterTableView.Items[e.Item.ItemIndex].Edit = true;

The issue is when I use the "FireCommandEvent" function, it doesn't set the ItemIndex. 

How do I fix this?

1 Answer, 1 is accepted

Sort by
0
HSD
Top achievements
Rank 1
answered on 28 Oct 2013, 06:24 PM
Well, I found a work around for now.  I use the CommandArgument to pass the ItemIndex and then pass that to my method.
Tags
Grid
Asked by
HSD
Top achievements
Rank 1
Answers by
HSD
Top achievements
Rank 1
Share this question
or