我正尝试使用teleriks rad网格执行插入操作。我正在做一个就地插入并使用onInsertCommand方法来设置要插入的值。我在telerik的文档中发现了这个说法:无法插入使用OnInsertCommand的Telerik RadGrid原地插入e.item
GridEditableItem editedItem = e.Item as GridEditableItem;当我使用它editedItem越来越空值,我不知道如何使它发挥作用:
这里是我的代码背后的InsertCommand
保护无效RadGrid1_InsertCommand(对象发件人,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 =“F ALSE” AllowAutomaticInserts = “假” 的DataKeyNames = “UnitTypeID” 网格线= “两者”
EditItemStyle-WIDTH = “24像素”> <% -
- % >
'runat =“server”ID =“Addnew”Text =“Add New”CommandName =“InitInsert”/> 'runat =“server”ID =“CancelAdd”Text =“Cancel”CommandName =“CancelAll” /> 'RUNAT = “服务器” ID = “InsertNew” 文本= “执行插入” 的CommandName = “PerformInsert”/>
' RUNAT = “服务器” ID = “EditAll” 文本= “编辑全部” CommandName =“EditAll”/> 0%>'runat =“server”ID =“CancelEdit”Text =“Cancel”CommandName =“CancelAll”/> 0%> runat =“server”ID =“UpdateAll “Text =”全部更新“CommandName =”UpdateAll“OnClientClick ='javascript:return confirm(”你是su再要更新所有记录?“)” />
<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>
请帮我做一个SUCESSFUL插入。
另外,Telerik的文档中我看到他们用e.ite.item
指数得到vdatakeyvalue但如果我用它索引总是显示为-1,所以我用editedItem.ItemIndex
和正常工作
在此先感谢