RadGrid FormEditTemplate auto update doesn't work

2 posts, 0 answers
  1. Henry
    Henry avatar
    1 posts
    Member since:
    Jul 2016

    Posted 29 Jul Link to this post

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"  />
        
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
         <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <div id="divfilter">
        <br />
        <uc1:UCDynamicFilter runat="server" ID="UCDynamicFilter1" />
        <br />
        </div>
        <div id="divdatatable" runat="server" >
            <br />
            <telerik:RadButton ID="RadBtnExp"  runat="server" Text="导出"   OnClick="RadBtnExp_Click"></telerik:RadButton>
            <telerik:RadGrid ID="RadGrid1" runat="server" ClientSettings-Scrolling-AllowScroll="true"   AllowSorting="True"  Height="500px"
                AllowPaging="true" AllowAutomaticUpdates="True" PageSize="30"  DataSourceID="SqlDataSourceSales"   AutoGenerateColumns="false" >
                <ClientSettings>
                    <Scrolling SaveScrollPosition="true" UseStaticHeaders="true" />
                </ClientSettings>
                <MasterTableView EditMode="EditForms" DataKeyNames="ID"  >          
                        <Columns>
                            <telerik:GridEditCommandColumn   UniqueName="EditCommandColumn"  ></telerik:GridEditCommandColumn>
                            <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID" DataType="System.Int32"    ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="年月" DataField ="年月" HeaderText="年月"  ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName ="公司名称" DataField="公司名称"  HeaderText="地区公司名称" ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName ="营销中心项目名称和分期" DataField ="营销中心项目名称和分期" HeaderText="营销项目名称和分期" ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="楼栋" DataField="楼栋" HeaderText ="楼栋"  ></telerik:GridBoundColumn>         
                            <telerik:GridBoundColumn UniqueName="物业类型"  DataField="物业类型" HeaderText="物业类型"  ForceExtractValue="Always" DataType="System.Char" ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName ="面积" DataField ="面积" HeaderText="面积(签订-退订)" DataFormatString="{0:N2}" ItemStyle-HorizontalAlign ="Right"  ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="金额" DataField ="金额" HeaderText="金额(签订-退订)"  DataFormatString="{0:N2}" ItemStyle-HorizontalAlign ="Right" ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="征收方式" DataField="征收方式" HeaderText="征收方式"  ForceExtractValue="Always" DataType="System.Char" ></telerik:GridBoundColumn>
                        </Columns>
                    <EditFormSettings  EditFormType="Template">
                        <FormTemplate>
                            <table id="Table1"  style="border-collapse: collapse;">
                                <tr>
                                    <td>地区公司名称</td>
                                    <td><asp:Label ID="LabelCompany" runat="server" Text ='<%# Bind("公司名称")%>'></asp:Label>  </td>
                                </tr>
                                <tr>
                                    <td>营销中心项目名称和分期</td>
                                    <td><asp:Label ID="LableProjectFq" runat="server" Text ='<%# Bind("营销中心项目名称和分期")%>'></asp:Label>  </td>
                                </tr>
                                <tr>
                                    <td>楼栋</td>
                                    <td><asp:Label ID="LabelBuilding" runat="server" Text ='<%# Bind("楼栋")%>'></asp:Label>  </td>
                                </tr>
                                <tr>
                                    <td>物业类型</td>
                                    <td>
                                        
                                        <asp:DropDownList ID="RDDListbulidingtype" runat="server" DataSourceID="SqlDataSource1" DataValueField="物业类型" DataTextField="物业类型"  SelectedValue ='<%# Bind("物业类型") %>'  AppendDataBoundItems="true" >
                                             <asp:ListItem Selected="True" Text="Select" Value="">
                                             </asp:ListItem>
                                        </asp:DropDownList>
                                        
                                    </td>
                                </tr>
                                <tr>
                                    <td> 面积</td>
                                    <td><asp:Label  ID="LabelArea" runat="server" Text ='<%# Bind("面积")%>'></asp:Label>  </td>
                                </tr>
                                <tr>
                                     <td> 金额</td>
                                    <td><asp:Label ID="LabelAmount" runat="server" Text ='<%# Bind("金额")%>'></asp:Label>  </td>
                                </tr>
                                <tr>
                                     <td>征收方式</td>
                                    <td>
                                        <telerik:RadDropDownList ID="RDDListTax" runat="server"  SelectedValue='<%# Bind("征收方式") %>' >
                                        <Items >
                                            <telerik:DropDownListItem Text="" Value="" />
                                            <telerik:DropDownListItem Text="简易" Value="简易" />
                                            <telerik:DropDownListItem Text="一般" Value="一般" />
                                        </Items>
                                        </telerik:RadDropDownList>
                                    </td>
                                   </tr>
                                <tr>
                                     <td><asp:Button ID="btnUpdate" runat="server" Text="保存" CommandName="Update" /></td>
                                     <td><asp:Button ID="btnCancel" runat="server" Text="取消" CommandName="Cancel" /></td>
                                </tr>
                            </table>
                        </FormTemplate>
                    </EditFormSettings>
                </MasterTableView>
              </telerik:RadGrid>
        </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"  ConnectionString="<%$ ConnectionStrings:myAsystemstring %>" SelectCommand="select * from 物业类型表"  ></asp:SqlDataSource>
        <asp:SqlDataSource  ID="SqlDataSourceSales" runat="server"  ConnectionString="<%$ ConnectionStrings:myAsystemstring %>"
            SelectCommand="select * from 销售导入表 where 公司名称=@mycompanyname and 项目名称=@myprojectname and 年月=@mydate "
            UpdateCommand ="update 销售导入表 set 物业类型=@buildingtype, 征收方式=@taxtype where ID=@ID">
                 <SelectParameters  >
                     <asp:ControlParameter Name="mycompanyname" ControlID="UCDynamicFilter1" PropertyName="FilterCompanyName" />
                     <asp:ControlParameter Name="myprojectname" ControlID="UCDynamicFilter1" PropertyName="FilterProjectName" />
                     <asp:ControlParameter Name="mydate" ControlID="UCDynamicFilter1" PropertyName="FliterDate" />
                 </SelectParameters>
                <UpdateParameters >
                    <asp:Parameter Name="buildingtype"  Type="String"  />
                    <asp:Parameter Name="taxtype" Type="String" />
                    <asp:Parameter Name="ID"  Type="Int32" />
                </UpdateParameters>
        </asp:SqlDataSource>

    </asp:Content>

    There is not code behind revalent to this part. The RadScriptManager is in the Master Page.
    I'm using Radgrid Control EditformTemplate and auto update (in my case I don't need delete, insert and data validation ), but update button doesn't work. I have check another thread work which says by using "Update" to commandName of button attribution it will be automatic. and demo which shows code behind only for validation.  The update action now seems only return null values to database. 

     

    Thanks in advance.

  2. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 03 Aug Link to this post

    Hello Henry,

    The SQL Update parameters like buildingtype and taxtype should have the same name as with the Bind expression parameter like Text property or SelectedValue ='<%# Bind("物业类型") %>' in order for the grid to pass the info properly:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/automatic-datasource-operations


    Regards,
    Eyup
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top