开发者

unable to insert Telerik RadGrid In-Place insert using OnInsertCommand e.item

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.GridCommandEvent开发者_StackOverflowArgs 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


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜