I posted my question as a reply by mistake (I am new here!!!)
I would be grateful if you guys could go over there and answer it? Thanks!
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-add-new-record.aspx#2756269
I would be grateful if you guys could go over there and answer it? Thanks!
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-add-new-record.aspx#2756269
3 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Aug 2013, 06:14 AM
Hello,
Thanks,
Jayesh Goyani
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JayeshTestConnectionString %>" SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Category]"></asp:SqlDataSource> <asp:UpdatePanel ID="updPnlRecList" RenderMode="Inline" runat="server" UpdateMode="Conditional" EnableViewState="true"> <ContentTemplate> <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" Visible="true" GridLines="None" AllowPaging="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource" AllowScroll="True" AllowFilteringByColumn="True" AllowMultiRowSelection="True" ItemStyle-VerticalAlign="Top" PageSize="25" AutoGenerateEditColumn="true" AutoGenerateDeleteColumn="true" AutoGenerateInsertColumn="true" AllowAutomaticInserts="false" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" OnItemDataBound="RadGrid1_ItemDataBound"> <MasterTableView CommandItemDisplay="Top" EditMode="EditForms" DataKeyNames="ID"> <Columns> <telerik:GridBoundColumn DataField="ID" ReadOnly="true" HeaderText="Product Id" Display="false" SortExpression="ID" /> <telerik:GridBoundColumn DataField="Name" ReadOnly="false" HeaderText="Product Name" Display="true" SortExpression="Name" /> </Columns> <EditFormSettings EditFormType="Template"> <FormTemplate> <table> <tr> <td width="125px"> Product: </td> <td> <asp:DropDownList ID="drpProduct" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="True"> <asp:ListItem Value="0">Select a Product..</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td width="125px"> Utility: </td> <td> <asp:DropDownList ID="drpUtility" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="True"> <asp:ListItem Value="0">Select a Utility..</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td width="125px"> IsDesktopActive: </td> <td> <asp:CheckBox ID="chkIsDesktopActive" runat="server" Checked='<%# Eval("IsDesktopActive") == DBNull.Value ? false : Convert.ToBoolean(Eval("IsDesktopActive")) %>' /> </td> </tr> <tr> <td width="125px"> IsMobileActive: </td> <td> <asp:CheckBox ID="chkIsMobileActive" runat="server" Checked='<%# Eval("IsDesktopActive") == DBNull.Value ? false : Convert.ToBoolean(Eval("IsDesktopActive")) %>' /> </td> </tr> <tr> <td width="125px"> IsTabletActive: </td> <td> <asp:CheckBox ID="chkIsTabletActive" runat="server" Checked='<%# Eval("IsDesktopActive") == DBNull.Value ? false : Convert.ToBoolean(Eval("IsDesktopActive")) %>' /> </td> </tr> <tr> <td align="right" colspan="2"> <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> </asp:Button> <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button> </td> </tr> </table> </FormTemplate> <PopUpSettings Modal="True" Width="650px"></PopUpSettings> </EditFormSettings> <NoRecordsTemplate> You currently have no listings in the system.</NoRecordsTemplate> </MasterTableView> <ClientSettings AllowGroupExpandCollapse="True" AllowDragToGroup="False" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder" ReorderColumnsOnClient="true"> <Animation AllowColumnReorderAnimation="true" ColumnReorderAnimationDuration="300" AllowColumnRevertAnimation="true" /> <Selecting AllowRowSelect="true" /> <Scrolling UseStaticHeaders="true" AllowScroll="true" ScrollHeight="550px" /> <Resizing AllowColumnResize="true" ClipCellContentOnResize="true" EnableRealTimeResize="true" /> </ClientSettings> </telerik:RadGrid> </ContentTemplate> </asp:UpdatePanel>protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { dynamic data1 = new[] { new { ID = 1, Name ="Name_1",IsDesktopActive=true}, new { ID = 2, Name = "Name_2",IsDesktopActive=false}, new { ID = 3, Name = "Name_1",IsDesktopActive=true}, new { ID = 4, Name = "Name_4",IsDesktopActive=true}, new { ID = 5, Name = "Name_1",IsDesktopActive=true} }; RadGrid1.DataSource = data1; } protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditFormItem item = e.Item as GridEditFormItem; if (e.Item is GridEditFormInsertItem) { } else { string strID = item.GetDataKeyValue("ID").ToString(); DropDownList drpProduct = item.FindControl("drpProduct") as DropDownList; drpProduct.SelectedValue = strID; DropDownList drpUtility = item.FindControl("drpUtility") as DropDownList; drpUtility.SelectedValue = strID; } } }Thanks,
Jayesh Goyani
0
michelle
Top achievements
Rank 1
answered on 22 Aug 2013, 10:30 AM
Thanks for this reply. So what was I doing wrong? The only thing I can see that's different is that the entity data source is not using entities? Is there a bug in rad grid when using entity data source on edit forms that use entity framework at the back end?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Aug 2013, 05:11 AM
Hello,
As per knowledge issue is binding method in edit/insert mode.
In edit mode value is there so it is able to bind this value in controls (checkbox/dropdownlist).
in InsertMode value is not there so it is not able to bind null in the selectedvalue/checked property. In checkbox i have put the null condition and in Dropdownlist i have set value from back-end.
Thanks,
Jayesh Goyani
As per knowledge issue is binding method in edit/insert mode.
In edit mode value is there so it is able to bind this value in controls (checkbox/dropdownlist).
in InsertMode value is not there so it is not able to bind null in the selectedvalue/checked property. In checkbox i have put the null condition and in Dropdownlist i have set value from back-end.
Thanks,
Jayesh Goyani