1

Here is the code I am using for delete functionality.

In RadgridItemdatabound funtion, I have to include this...

foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
                {
                    dataItem["TemplateDeleteColumn"].Attributes.Add("onclick","CellClick('" + dataItem.ItemIndex + "','" + col.UniqueName + "');");
                }

Then I have to create Itemcommand function.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "DeleteSelected")
        {
            GridDataItem item = (GridDataItem)e.Item;
            var itemIndex = item.ItemIndex;
            string LoginId = item.GetDataKeyValue("LoginId").ToString();
            Int32 CampusCode = Convert.ToInt32(item.GetDataKeyValue("CampusCode"));


            Definations def = new Definations();
            Int32 Result = def.deleteUserAssignCampus(LoginId, CampusCode);
            if (Result == 1)
            {
                BindDeptDatasimple();

                cmbColumName.SelectedValue = "";
                cmbDirection.SelectedValue = "";
                Response.Redirect("UserCampus.aspx", false);
                Session["deleteUserCampus"] = "Campus dissociated successfully.";
            }
        }
    }

I could not get index of the selected row in the "var ItemIndex". It always return zero index in ItemIndex. That's why the first row from the grid gets deleted. How I can get selected Index of selected row?

1 Answers1

0

The item index will default to 0 because in your case you raise custom command through MasterTableView's client object method.

You will have to make sure that in your custom JS function, CellClick, item index is passed into fireCommand client method via the 2nd argument.

masterTable.fireCommand("DeleteSelected", itemIndex); 

Then in RadGrid1_ItemCommand event handler, you can retrieve the index value like this

GridDataItem item = (GridDataItem)e.Item;
var itemIndex = e.CommandArgument;
woodykiddy
  • 6,074
  • 16
  • 59
  • 100