This is a migrated thread and some comments may be shown as answers.

Problems with RadGrid autoUpdates

4 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tal
Top achievements
Rank 1
Tal asked on 05 Aug 2013, 08:35 AM
Hey,
I cannot at all update my radGrid. Tried possibly everything.

Please help me find out why. I simplified the problem to the following code.
Its only a little table of two columns, the key is seasonID.
I even tried to write the UpdateCommand manually and add the updateParameters. Nothing works,
I've been spending hours on this little thing. 

Thank you very much for your help!!

 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.Core.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQuery.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQueryInclude.js">
            </asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <div>
     
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
            AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="True"
            AutoGenerateEditColumn="True" CellSpacing="0" DataSourceID="SqlDataSource1"
            GridLines="None">
            <ClientSettings>
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            </ClientSettings>
<MasterTableView AutoGenerateColumns="False" DataKeyNames="seasonID"
                DataSourceID="SqlDataSource1">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
 
    <Columns>
        <telerik:GridBoundColumn DataField="seasonID" DataType="System.Int32"
            FilterControlAltText="Filter seasonID column" HeaderText="seasonID"
            ReadOnly="True" SortExpression="seasonID" UniqueName="seasonID" ForceExtractValue="Always">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="seasonName"
            FilterControlAltText="Filter seasonName column" HeaderText="seasonName"
            SortExpression="seasonName" UniqueName="seasonName" ForceExtractValue="Always">
        </telerik:GridBoundColumn>
    </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
 
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
 
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:tm2013ConnectionString %>"
              UpdateCommand = "UPDATE [tblseasons] SET [seasonName]=@seasonName where [seasonID]=@seasonID"
               SelectCommand="SELECT * FROM [tblseasons]">
             
            <UpdateParameters>
            <asp:Parameter Name="seasonName" Type="String" />
            <asp:Parameter Name="seasonID" Type="Int32" />
            </UpdateParameters>
              </asp:SqlDataSource>
     
    </div>
    </form>
</body>
</html>



4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Aug 2013, 08:44 AM
Hello,

Please add below property in your grid.

AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" AllowAutomaticInserts="true"


Thanks,
Jayesh Goyani
0
Tal
Top achievements
Rank 1
answered on 05 Aug 2013, 08:54 AM
Hey,
 thanks so much for your quick help, actually in this small page it worked now.

I have other page in which those properties were activated and it isn't working either.

I would appreciate your help again.

Thank you!

<%@ Page Title="" Language="C#" MasterPageFile="~/northTheatre.Master" AutoEventWireup="true" CodeBehind="seasonsList.aspx.cs" Inherits="RadControlsWebApp2.seasonsList" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
     
       
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" UpdateInitiatorPanelsOnly="True">
    </telerik:RadAjaxManager>
  <p>
         </p>
    <asp:Panel ID="Panel2" runat="server" Height="91px" style="margin-right: 243px; padding-right:100px;"
        Width="750px">
        <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True"
            AllowSorting="True" CellSpacing="0" DataSourceID="SqlDataSource1"
            GridLines="None"  Skin="Office2007"
            >
            <SortingSettings SortToolTip="לחץ כאן כדי למיין" />
            <ExportSettings>
                <Pdf PageHeight="297mm" PageWidth="210mm" PaperSize="A4" />
            </ExportSettings>
            <ClientSettings>
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
<MasterTableView AutoGenerateColumns="False" DataKeyNames="seasonID,seasonName"
                DataSourceID="SqlDataSource1">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
 
        <Columns>
          <telerik:GridEditCommandColumn ButtonType="PushButton">
                  </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="seasonID" DataType="System.Int32"
                FilterControlAltText="Filter seasonID column" HeaderText="קוד עונה"
                SortExpression="seasonID" UniqueName="seasonID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="seasonName"
                FilterControlAltText="Filter seasonName column" HeaderText="שם עונה"
                SortExpression="seasonName" UniqueName="seasonName">
            </telerik:GridBoundColumn>
 
        </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
 
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
 
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:tm2013ConnectionString %>"
            UpdateCommand = "UPDATE [tblseasons] SET [seasonName]=@seasonName where [seasonID]=@seasonID"
            SelectCommand="SELECT [seasonID], [seasonName] FROM [tblseasons]">
            <UpdateParameters>
            <asp:Parameter Name="seasonName" Type="String" />
            <asp:Parameter Name="seasonID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
     
    </div>
     
    <telerik:RadButton ID="delButton" runat="server" onclick="delButton_Click"
        Text="מחק רשומה נוכחית" Skin="Office2007">
    </telerik:RadButton>
      
    <telerik:RadButton ID="addNewSeason_btn" runat="server"
      
         Text="הוסף עונה חדשה" onclick="addNewSeason_Click">
    </telerik:RadButton>
       
   
    </asp:Panel>
    </asp:Panel>
</asp:Content>

0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Aug 2013, 09:41 AM
Hi Tal,

You are not able to Update because you have set both seasonID and seasonName as DataKeyNames,so they are not editable.please try setting only seasonID as DataKeyNames,so that you can edit seasonName . Here seasonID acts as a unique field to identify the rows.We usually set values for DataKeyNames as those columns that are not needed to edit but for reference,somewhat like primary key column to identify the rows from each other.
Hope this helps.

Thanks,
Princy
0
Tal
Top achievements
Rank 1
answered on 05 Aug 2013, 09:47 AM
Thank you, it is working!!! Finally :)
Tags
Grid
Asked by
Tal
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Tal
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or