Hi
I'm working on moving some of our grids from using the auto generated edit forms to using Form Templates, but still using the markup for defining the CRUD operations using the SqlDataSource.
The grids already use asp:SqlDataSource for the CRUD operations and have been working fine with the auto-generated edit forms.
I've now changed the markups and added the FormTemplate which shows the insert / edit form as expected, including binding the column values correctly when editing, but the insert / update operations do not work from these forms.
When I try to insert a record, it simply creates a record with NULL values.
When I try to update record, I get the following error (I have the ConflictDetection set to CompareAllValues):
"You have specified that your update command compares all values on SqlDataSource 'sqlOperatorNotes', but the dictionary passed in for oldValues is empty. Pass in a valid dictionary for update or change your mode to OverwriteChanges"
Seems like the control values are not being passed from the edit/insert form to the sqldatasourc.
Do I need to change anything more to switch from auto generated edit forms to FormTemplates.
Here's part of the formtemplate:
Here's the corresponding grid column
I'm working on moving some of our grids from using the auto generated edit forms to using Form Templates, but still using the markup for defining the CRUD operations using the SqlDataSource.
The grids already use asp:SqlDataSource for the CRUD operations and have been working fine with the auto-generated edit forms.
I've now changed the markups and added the FormTemplate which shows the insert / edit form as expected, including binding the column values correctly when editing, but the insert / update operations do not work from these forms.
When I try to insert a record, it simply creates a record with NULL values.
When I try to update record, I get the following error (I have the ConflictDetection set to CompareAllValues):
"You have specified that your update command compares all values on SqlDataSource 'sqlOperatorNotes', but the dictionary passed in for oldValues is empty. Pass in a valid dictionary for update or change your mode to OverwriteChanges"
Seems like the control values are not being passed from the edit/insert form to the sqldatasourc.
Do I need to change anything more to switch from auto generated edit forms to FormTemplates.
Here's part of the formtemplate:
<Telerik:Radtextbox ID="notesbox" runat="server" Text='<%# Bind("Note") %>' Width="150px"> </Telerik:Radtextbox>Here's the corresponding grid column
<telerik:GridBoundColumn UniqueName="Note" SortExpression="Note" HeaderText="Note" HeaderStyle-VerticalAlign="Top" HeaderButtonType="TextButton" DataField="Note" ItemStyle-VerticalAlign="Top">7 Answers, 1 is accepted
0
mqsash
Top achievements
Rank 1
answered on 03 Apr 2013, 10:22 PM
Additional informaiton...
I intercepted the OnInserting event of the SqlDataSource being used and found that when the Insert button is clicked this function does get called, it also has all the parameters listed in the "InsertParameters" of the SqlDataSource but when called from the edit template form, the parameter values are blank.
When called from the auto generated edit forms, these parameters contain the Values from the corresponding controls on the auto forms.
So the question is why is there no value when called from the form templates.
Seems like the bi-directional binding [<%# Bind("Note") %>] is only working in one direction :(
I intercepted the OnInserting event of the SqlDataSource being used and found that when the Insert button is clicked this function does get called, it also has all the parameters listed in the "InsertParameters" of the SqlDataSource but when called from the edit template form, the parameter values are blank.
When called from the auto generated edit forms, these parameters contain the Values from the corresponding controls on the auto forms.
So the question is why is there no value when called from the form templates.
Seems like the bi-directional binding [<%# Bind("Note") %>] is only working in one direction :(
0
mqsash
Top achievements
Rank 1
answered on 04 Apr 2013, 06:37 PM
I think I have found the missing link!!!! J
It all comes down to one line in the markup of the edit form, and that is specifying the runat=”server” for the table used in the Form Template.
I can make the insert / update work (or not) from the form template by simply removing or including the runat="server".
<FormTemplate> <table id="Table10" cellspacing="1" cellpadding="1" runat="server" ---------insert / update does not work when this is included!!!! width="100%"> <tr> ...template markup goes here... </tr> </table></FormTemplate>Is this a telerik bug or is this how the asp.net bi-directional binding works?
mqs
0
Hello,
Basically you should not set the runat="server" property when using Form Template. Could you please provide us with your code declaration and the related code behind in order to get a better idea how is your RadGrid declared? Additionally you could check out the following live example where is demonstrated RadGrid - Form Template Edit Form.
All the best,
Kostadin
the Telerik team
Basically you should not set the runat="server" property when using Form Template. Could you please provide us with your code declaration and the related code behind in order to get a better idea how is your RadGrid declared? Additionally you could check out the following live example where is demonstrated RadGrid - Form Template Edit Form.
All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
mqsash
Top achievements
Rank 1
answered on 08 Apr 2013, 06:09 PM
Hi
My markup is a bit too long to paste here, but almost exactly the same as the same as that in the "live example" link that you have provided.
The only differences being that my markup uses a DataSourceID to an asp:SqlDataSource which uses stored procedures to select, insert, update and delete the records. (your examples have straight sql statements). There is no code behind at all related to the grid editing at all.
The edit form is a pop-up.
While creating the form template we created the <table> with the runat="server" out of habit but like you said we probably should not use the runat="server" on the form templates. Is it because the controls in the formtemplate get rendered differently than regular controls on the page, if so how?
Thanks
mqs
My markup is a bit too long to paste here, but almost exactly the same as the same as that in the "live example" link that you have provided.
The only differences being that my markup uses a DataSourceID to an asp:SqlDataSource which uses stored procedures to select, insert, update and delete the records. (your examples have straight sql statements). There is no code behind at all related to the grid editing at all.
The edit form is a pop-up.
While creating the form template we created the <table> with the runat="server" out of habit but like you said we probably should not use the runat="server" on the form templates. Is it because the controls in the formtemplate get rendered differently than regular controls on the page, if so how?
Thanks
mqs
0
Hello,
I am afraid but without your code declaration it is hard to pinpoint the reason for that behavior. I believe that both rendering are identical and the reason might be related with something else.
All the best,
Kostadin
the Telerik team
I am afraid but without your code declaration it is hard to pinpoint the reason for that behavior. I believe that both rendering are identical and the reason might be related with something else.
All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Harry
Top achievements
Rank 1
answered on 22 May 2013, 04:18 PM
Hi,
I am having the same issue. Below is my code. Please let me know what the issue is. I am using an update stored procedure and I know it is calling the SP; however it is passing null values.
I am having the same issue. Below is my code. Please let me know what the issue is. I am using an update stored procedure and I know it is calling the SP; however it is passing null values.
<%@ Page Title="" Language="C#" MasterPageFile="~/UI Tier/CM.Master" AutoEventWireup="true" CodeBehind="Products.aspx.cs" Inherits="ConflictMinerals.UI_Tier.WebForm4" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <style type="text/css"> /* Example Css Class for your reference */ div.rgEditForm { border: 1px solid; width: 500px; } .t-edit-form-container { width: 200px; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server" > <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" EnableRoundedCorners="true" DecoratedControls="Buttons, Textbox, Label, GridFormDetailsViews" EnableTheming="False" /> <asp:TextBox ID="TextBox1" runat="server" BackColor="White" CssClass="auto-style1" Width="372px"></asp:TextBox> <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="3" DataSourceID="sqlProducts" GridLines="None" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AllowSorting="True" PageSize="50" ShowFooter="True" Skin="Office2010Black" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound" CellPadding="0" > <ExportSettings ExportOnlyData="True" OpenInNewWindow="True"> </ExportSettings> <MasterTableView DataSourceID="sqlProducts" AutoGenerateColumns="False" DataKeyNames="EY_Prod_PK" EditMode="PopUp" CommandItemDisplay="Top"> <CommandItemSettings ExportToPdfText="Export to PDF" ShowExportToExcelButton="True" ShowExportToPdfButton="True"> </CommandItemSettings> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> <HeaderStyle Width="20px"></HeaderStyle> </RowIndicatorColumn> <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column" Created="True"> <HeaderStyle Width="20px"></HeaderStyle> </ExpandCollapseColumn> <Columns> <telerik:GridBoundColumn DataField="EY_Prod_PK" DataType="System.Int32" FilterControlAltText="Filter EY_Prod_PK column" HeaderText="EY_Prod_PK" ReadOnly="True" SortExpression="EY_Prod_PK" UniqueName="EY_Prod_PK" Visible="False"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="EY_Vendor_PK" FilterControlAltText="Filter EY_Vendor_PK column" HeaderText="EY_Vendor_PK" SortExpression="EY_Vendor_PK" UniqueName="EY_Vendor_PK" ItemStyle-Width="20%" DataType="System.Int32" Display="False"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> <ItemStyle Width="20%"></ItemStyle> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Product_Category" FilterControlAltText="Filter Product_Category column" HeaderText="Product_Category" SortExpression="Product_Category" UniqueName="Product_Category" ItemStyle-Width="40%"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> <FilterTemplate> <asp:TextBox ID="TextBox1" runat="server" Height="17px" Text='<%# Bind("Product_Category") %>' Width="375px"></asp:TextBox> </FilterTemplate> <ItemStyle Width="15%"></ItemStyle> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Product_Category_Description" FilterControlAltText="Filter Product_Category_Description column" HeaderText="Product_Category_Description" SortExpression="Product_Category_Description" UniqueName="Product_Category_Description" ItemStyle-Width="40%"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> <ItemStyle Width="20%" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Product_Number" FilterControlAltText="Filter Product_Number column" HeaderText="Product_Number" SortExpression="Product_Number" UniqueName="Product_Number"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> <ItemStyle Width="15%" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Product_Description" FilterControlAltText="Filter Product_Description column" HeaderText="Product_Description" SortExpression="Product_Description" UniqueName="Product_Description"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> <ItemStyle Width="20%" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Comment" FilterControlAltText="Filter Comment column" HeaderText="Comment" SortExpression="Comment" UniqueName="Comment"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> <ItemStyle Width="30%" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Date_Inserted" DataType="System.DateTime" FilterControlAltText="Filter Date_Inserted column" HeaderText="Date_Inserted" SortExpression="Date_Inserted" UniqueName="Date_Inserted" Visible="False"> <ColumnValidationSettings> <ModelErrorMessage Text="" /> </ColumnValidationSettings> </telerik:GridBoundColumn> </Columns> <EditFormSettings editformtype="Template" PopUpSettings-Modal="true" PopUpSettings-Width="50%" PopUpSettings-Height="30%" CaptionFormatString="Please Enter Product Information:" FormCaptionStyle-HorizontalAlign="Center" FormMainTableStyle-CellPadding="2" FormMainTableStyle-CellSpacing="2"> <EditColumn UniqueName="EditCommandColumn" FilterControlAltText="Filter EditCommandColumn column"></EditColumn> <FormStyle Width="100%"> </FormStyle> <FormCaptionStyle HorizontalAlign="Center"></FormCaptionStyle> <FormTableItemStyle Wrap="False"></FormTableItemStyle> <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="0" Width="1500px"></FormMainTableStyle> <FormTemplate > <table id="tblProduct" runat="server" style="border: thin solid gray; width:100%; height:100%; background-color: #35434b; font-family: 'Arial'"> <tr> <td style="width: 2%; height:5%"> <asp:TextBox ID="TextBox3" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.EY_Prod_PK" ) %>'></asp:TextBox> </td> <td style="width: 34%"> </td> <td style="width: 2%"> </td> <td style="width: 60%"> </td> <td style="width: 2%"> </td> </tr> <tr> <td style="width: 2%; height:5%"> <asp:TextBox ID="TextBox2" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.EY_Vendor_PK" ) %>'></asp:TextBox> </td> <td style="width: 34%"> </td> <td style="width: 2%"> </td> <td style="width: 60%"> </td> <td style="width: 2%"> </td> </tr> <tr> <td style="width: 2%"> </td> <td style="width: 34%"> <asp:Label ID="lblProductCategory" runat="server" Font-Size="9pt" ForeColor ="#aaaaaa" Text="Product Category"></asp:Label> </td> <td style="width: 2%"> </td> <td style="width: 60%"> <asp:TextBox ID="txtProductCategory" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.Product_Category" ) %>'></asp:TextBox> </td> <td style="width: 2%"> <%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Static" ErrorMessage="*" ControlToValidate="txtProductCategory" Font-Size="Large" ForeColor="#FF3300"></asp:RequiredFieldValidator>--%> </td> </tr> <tr> <td style="width: 2%"> </td> <td style="width: 34%"> <asp:Label ID="lblProductCategoryDescription" runat="server" Font-Size="9pt" ForeColor ="#aaaaaa" Text="Product Category Description"></asp:Label> </td> <td style="width: 2%"> </td> <td style="width: 60%"> <asp:TextBox ID="txtProductCategoryDescription" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.Product_Category_Description" ) %>'></asp:TextBox> </td> <td style="width: 2%"> <%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Static" ErrorMessage="*" ControlToValidate="txtProductCategoryDescription" Font-Size="Large" ForeColor="#FF3300"></asp:RequiredFieldValidator>--%> </td> </tr> <tr> <td style="width: 2%"> </td> <td style="width: 34%"> <asp:Label ID="lblProductNumber" runat="server" Font-Size="9pt" ForeColor ="#aaaaaa" Text="Product Number"></asp:Label> </td> <td style="width: 2%"> </td> <td style="width: 80%"> <asp:TextBox ID="txtProductNumber" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.Product_Number" ) %>'></asp:TextBox> </td> <td style="width: 2%"> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="Static" ErrorMessage="*" ControlToValidate="txtProductNumber" Font-Size="Large" ForeColor="#FF3300" Font-Bold="True"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 2%"> </td> <td style="width: 34%"> <asp:Label ID="lblProductDescription" runat="server" Font-Size="9pt" ForeColor ="#aaaaaa" Text="Product Description"></asp:Label> </td> <td style="width: 2%"> </td> <td style="width: 60%"> <telerik:RadTextBox ID="txtProductDescription" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.Product_Description" ) %>' Height="100"></telerik:RadTextBox> </td> <td style="width: 2%; text-align:left"> <%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" Display="Static" ErrorMessage="*" ControlToValidate="txtProductDescription" Font-Size="Large" ForeColor="#FF3300"></asp:RequiredFieldValidator>--%> </td> </tr> <tr> <td style="width: 2%"> </td> <td style="width: 34%"> <asp:Label ID="lblComment" runat="server" Font-Size="9pt" ForeColor ="#aaaaaa" Text="Comment"></asp:Label> </td> <td style="width: 2%"> </td> <td style="width: 60%"> <telerik:RadTextBox ID="txtComment" runat="server" Width="100%" Text='<%# DataBinder.Eval( Container, "DataItem.Comment" ) %>' Height="150"></telerik:RadTextBox> </td> <td style="width: 2%"> </td> </tr> <tr> <td style="width: 2%"> </td> <td style="width: 34%"> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" Display="Static" ErrorMessage="* Required Field" ControlToValidate="txtProductNumber" Font-Size="Small" ForeColor="#FF3300" Font-Bold="True"></asp:RequiredFieldValidator> </td> <td style="width: 2%"> </td> <td align="right" colspan="2"> <asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> </asp:Button> <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="True" CommandName="Cancel"> </asp:Button> </td> <td style="width: 2%"> </td> </tr> <tr> <td style="width: 2%; height:5%"> </td> <td style="width: 34%"> </td> <td style="width: 2%"> </td> <td style="width: 60%"> </td> <td style="width: 2%"> </td> </tr> </table> </FormTemplate> <PopUpSettings ScrollBars="None" /> </EditFormSettings> <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle> </MasterTableView> <EditItemStyle Width="900px" /> <ItemStyle Width="900px" /> <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle> <FilterMenu EnableImageSprites="False"> </FilterMenu> </telerik:RadGrid> <asp:SqlDataSource ID="sqlProducts" runat="server" ConnectionString="<%$ ConnectionStrings:ConflictMinerals %>" SelectCommand="SELECT * FROM Questionaire.[Product_List]" DeleteCommand="DELETE FROM Questionaire.[Product_List] WHERE [EY_Prod_PK] = @EY_Prod_PK" InsertCommand="Products.AddNewProducts" UpdateCommand="UPDATE Questionaire.[Product_List] SET [EY_Vendor_PK] = @EY_Vendor_PK, [Product_Category] = @Product_Category, [Product_Category_Description] = @Product_Category_Description, [Product_Number] = @Product_Number, [Product_Description] = @Product_Description, [Comment] = @Comment, [Date_Inserted] = @Date_Inserted WHERE [EY_Prod_PK] = @EY_Prod_PK" InsertCommandType="StoredProcedure"> <DeleteParameters> <asp:Parameter Name="EY_Prod_PK" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="EY_Vendor_PK" Type="Int32" /> <asp:Parameter Name="Product_Category" Type="String" /> <asp:Parameter Name="Product_Category_Description" Type="String" /> <asp:Parameter Name="Product_Number" Type="String" /> <asp:Parameter Name="Product_Description" Type="String" /> <asp:Parameter Name="Comment" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="EY_Vendor_PK" Type="Int32" /> <asp:Parameter Name="Product_Category" Type="String" /> <asp:Parameter Name="Product_Category_Description" Type="String" /> <asp:Parameter Name="Product_Number" Type="String" /> <asp:Parameter Name="Product_Description" Type="String" /> <asp:Parameter Name="Comment" Type="String" /> <asp:Parameter Name="Date_Inserted" Type="DateTime" /> <asp:Parameter Name="EY_Prod_PK" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> <telerik:RadScriptManager ID="RadScriptManager1" Runat="server"> </telerik:RadScriptManager> </asp:Content> 0
Hello Harry,
When using Automatic DataSource operations, use the Bind() syntax to bind template controls. This allows the grid to extract updated values and pass them to the data source with no additional code on your part.
Regards,
Kostadin
Telerik
When using Automatic DataSource operations, use the Bind() syntax to bind template controls. This allows the grid to extract updated values and pass them to the data source with no additional code on your part.
Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.