【问题标题】:Delete a row from Telerik Radgrid. How I get Index of that selected Row?从 Telerik Radgrid 中删除一行。我如何获得该选定行的索引?
【发布时间】:2016-07-01 05:09:01
【问题描述】:

这是我用于删除功能的代码。

在 RadgridItemdatabound 函数中,我必须包含这个...

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

然后我必须创建 Itemcommand 函数。

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.";
            }
        }
    }

我无法在“var ItemIndex”中获取所选行的索引。 它总是在 ItemIndex 中返回零索引。这就是网格中第一行被删除的原因。如何获取选定行的选定索引?

【问题讨论】:

    标签: telerik radgrid delete-row itemdatabound itemcommand


    【解决方案1】:

    项目索引将默认为 0,因为在您的情况下,您提出了自定义命令 通过 MasterTableView 的客户端对象方法。

    您必须确保在您的自定义 JS 函数 CellClick 中,项目索引通过第二个参数传递给 fireCommand 客户端方法。

    masterTable.fireCommand("DeleteSelected", itemIndex); 
    

    然后在RadGrid1_ItemCommand事件处理程序中,你可以像这样检索索引值

    GridDataItem item = (GridDataItem)e.Item;
    var itemIndex = e.CommandArgument;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 2012-01-13
      • 2018-04-03
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 2011-12-13
      相关资源
      最近更新 更多