无法使用 OnInsertCommand e.item 插入 Telerik RadGrid 就地插入

发布于 2024-11-06 02:48:26 字数 3743 浏览 5 评论 0原文

我正在尝试使用 Teleriks rad 网格执行插入。我正在执行就地插入并使用 onInsertCommand 方法来设置要插入的值。我在 telerik 的文档中找到了这个声明:

GridEditableItemeditedItem = e.Item as GridEditableItem;当我使用它时,editedItem 获取空值,我不知道如何使其工作:

这是我的 InsertCommand

protected void RadGrid1_InsertCommand(Object Sender, Telerik.Web.UI.GridCommandEventArgs e) 背后的代码 {

        GridEditableItem editedItem = e.Item as GridEditableItem;

        Hashtable newValues = new Hashtable();

        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
        editedItem.Edit = false;

        Yieldco.RS.Libraries.BusinessObjects.UnitType u1 = new Yieldco.RS.Libraries.BusinessObjects.UnitType();

        u1.Description = newValues["Description"].ToString();

        u1.UnitTypeID = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["UnitTypeID"]);
        u1.CommunityID = 1;
        u1.CompanyID = 1;
        u1.Bathrooms = (float)Convert.ToDouble(newValues["Bathrooms"]);
        u1.Bedrooms = Convert.ToInt32(newValues["Bedrooms"]);
        u1.SqFtHigh = (float)Convert.ToDouble(newValues["SqFtHigh"]);
        u1.SqFtLow = (float)Convert.ToDouble(newValues["SqFtLow"]);
        u1.NumOfUnits = Convert.ToInt32(newValues["NumOfUnits"]);
        u1.ProCon = Convert.ToInt32(newValues["ProCon"]);
        u1.OthCon = Convert.ToInt32(newValues["OthCon"]);
        u1.RentHigh = (float)Convert.ToDouble(newValues["RentHigh"]);
        u1.RentLow = (float)Convert.ToDouble(newValues["RentLow"]);
        u1.Status = 1;

        int id = MSController.SaveUnitTypes(u1);
}

和我的 aspx radgrid


AutoGenerateColumns=“假”AllowAutomaticUpdates=“假”AllowAutomaticInserts=“假”DataKeyNames=“UnitTypeID”GridLines=“两者”
EditItemStyle-Width="24px"> <%--
--%>
' runat="server" ID="Addnew" Text="新增" CommandName="InitInsert" /> ' runat="server" ID="CancelAdd" Text="Cancel" CommandName="CancelAll" //>     ' runat="server" ID="InsertNew" Text="执行插入" CommandName="PerformInsert" />  
' runat="server" ID="EditAll" Text="编辑全部" CommandName="EditAll" /> 0%>' runat="server" ID="CancelEdit" Text="取消" CommandName="CancelAll" //>   0%>' runat="server" ID="UpdateAll" Text="更新全部" CommandName="UpdateAll" OnClientClick='javascript:return inform("您确定要更新所有记录吗?")' />

     <asp:ObjectDataSource ID="odsGetUnitTypes" runat="server"
    TypeName="Yieldco.RS.Libraries.Controllers.MSController" 
    DataObjectTypeName="Yieldco.RS.Libraries.BusinessObjects.UnitType" 
    SelectMethod="GetUnitTypesByCommunityID"
    InsertMethod="SaveUnitTypes"
    UpdateMethod="SaveUnitTypes"
    >
    <SelectParameters>          
        <asp:Parameter DefaultValue="1" Name="CommunityID" />            
    </SelectParameters>
    </asp:ObjectDataSource>

请帮助我成功插入。

另外,在 Telerik 文档中,我看到他们使用 e.ite.item 索引来获取 vdatakeyvalue,但如果我使用它,索引总是显示为 -1,所以我使用 editedItem.ItemIndex< /code> 效果很好

提前致谢

I am trying to perform an insert using teleriks rad grid. I am doing an in-place insert and using the onInsertCommand method to set the values that are to be insertted. i found this statement in telerik's documnetation:

GridEditableItem editedItem = e.Item as GridEditableItem; when i use it editedItem is getting null value and i dont know how to make it work:

Here is my code behind for InsertCommand

protected void RadGrid1_InsertCommand(Object Sender, Telerik.Web.UI.GridCommandEventArgs e)
{

        GridEditableItem editedItem = e.Item as GridEditableItem;

        Hashtable newValues = new Hashtable();

        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
        editedItem.Edit = false;

        Yieldco.RS.Libraries.BusinessObjects.UnitType u1 = new Yieldco.RS.Libraries.BusinessObjects.UnitType();

        u1.Description = newValues["Description"].ToString();

        u1.UnitTypeID = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["UnitTypeID"]);
        u1.CommunityID = 1;
        u1.CompanyID = 1;
        u1.Bathrooms = (float)Convert.ToDouble(newValues["Bathrooms"]);
        u1.Bedrooms = Convert.ToInt32(newValues["Bedrooms"]);
        u1.SqFtHigh = (float)Convert.ToDouble(newValues["SqFtHigh"]);
        u1.SqFtLow = (float)Convert.ToDouble(newValues["SqFtLow"]);
        u1.NumOfUnits = Convert.ToInt32(newValues["NumOfUnits"]);
        u1.ProCon = Convert.ToInt32(newValues["ProCon"]);
        u1.OthCon = Convert.ToInt32(newValues["OthCon"]);
        u1.RentHigh = (float)Convert.ToDouble(newValues["RentHigh"]);
        u1.RentLow = (float)Convert.ToDouble(newValues["RentLow"]);
        u1.Status = 1;

        int id = MSController.SaveUnitTypes(u1);
}

and my aspx radgrid

AutoGenerateColumns="false" AllowAutomaticUpdates="false" AllowAutomaticInserts="false" DataKeyNames="UnitTypeID" GridLines="Both"
EditItemStyle-Width="24px">

<%--
--%>

' runat="server" ID="Addnew" Text="Add New" CommandName="InitInsert" />
' runat="server" ID="CancelAdd" Text="Cancel" CommandName="CancelAll" />  
' runat="server" ID="InsertNew" Text="Perform Insert" CommandName="PerformInsert" />  
' runat="server" ID="EditAll" Text="Edit All" CommandName="EditAll" />
0 %>' runat="server" ID="CancelEdit" Text="Cancel" CommandName="CancelAll" />  
0 %>' runat="server" ID="UpdateAll" Text="Update All" CommandName="UpdateAll" OnClientClick='javascript:return confirm("Are you sure you want to Update All Records?")' />

     <asp:ObjectDataSource ID="odsGetUnitTypes" runat="server"
    TypeName="Yieldco.RS.Libraries.Controllers.MSController" 
    DataObjectTypeName="Yieldco.RS.Libraries.BusinessObjects.UnitType" 
    SelectMethod="GetUnitTypesByCommunityID"
    InsertMethod="SaveUnitTypes"
    UpdateMethod="SaveUnitTypes"
    >
    <SelectParameters>          
        <asp:Parameter DefaultValue="1" Name="CommunityID" />            
    </SelectParameters>
    </asp:ObjectDataSource>

Please help me out to make a sucessful insertion.

Also in the Telerik documentation I saw them using e.ite.item index for getting the vdatakeyvalue but if I use it the index is always showing up as -1 so I used editedItem.ItemIndex and it works fine

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜巴黎 2024-11-13 02:48:26

要引用插入项,您应该使用以下语法(而不是编辑项):

if(e.CommandName = RadGrid.PerformInsertCommandName)
{
  GridEditableItem editItem = e.Item.OwnerTableView.GetInsertItem();
}

To reference the insert item, you should use the following syntax (as opposed to edited item):

if(e.CommandName = RadGrid.PerformInsertCommandName)
{
  GridEditableItem editItem = e.Item.OwnerTableView.GetInsertItem();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文