Unable to update underlying datasource

5 posts, 0 answers
  1. Dan Harvey
    Dan Harvey avatar
    67 posts
    Member since:
    Jul 2008

    Posted 14 Mar 2012 Link to this post

    Hello,

    I am using a RadGrid and I am binding an Arraylist of type "myClass" (name property, id Property and several boolean properties).  I am using this arrayList as my datasource for the grid and I am using checkbox columns for the boolean properties.

    public interface IMyClass
        {     
               int EntityID{get; set; }
            string Name { get; set; }
            bool IsPrivateReader { get; set; }
            bool CanShare { get; set; }
        }

    The issue I am having is that when I check a checkbox it does not update the object it is bound to.  Please help.  Here is my grid:

    <telerik:RadGrid ID="dg" 
                                 runat="server" 
                                 AllowSorting="True" 
                                 AllowAutomaticUpdates="True"
                                 Skin="WebBlue" 
                                 EnableAJAX="true" 
                                 EnableOutsideScripts="true" 
                                 GridLines="None">
                 <ClientSettings>
                     <Selecting CellSelectionMode="None" />
                 </ClientSettings>
                 <MasterTableView AllowAutomaticDeletes="true" AutoGenerateColumns="False" 
                     CommandItemDisplay="None" DataKeyNames="EntityID" Width="100%">
                     <CommandItemSettings ExportToPdfText="Export to PDF" />
                     <RowIndicatorColumn>
                         <HeaderStyle Width="20px" />
                     </RowIndicatorColumn>
                     <ExpandCollapseColumn>
                         <HeaderStyle Width="20px" />
                     </ExpandCollapseColumn>
                     <Columns>
                           
                         <telerik:GridBoundColumn DataField="EntityID" HeaderStyle-HorizontalAlign="Center" HeaderText="Entity ID" ItemStyle-HorizontalAlign="Left" SortExpression="EntityID">
                             <HeaderStyle HorizontalAlign="Center" />
                             <ItemStyle HorizontalAlign="Left" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Name" HeaderStyle-HorizontalAlign="Center" HeaderText="Name" ItemStyle-HorizontalAlign="Left" SortExpression="Name">
                             <HeaderStyle HorizontalAlign="Center" />
                             <ItemStyle HorizontalAlign="Left" />
                         </telerik:GridBoundColumn>
                         <telerik:GridTemplateColumn headertext="Private Reader" uniquename="PrivateReaderColumn">
                             <itemtemplate>
                                 <asp:CheckBox ID="cbxPrivateReader" runat="server" checked='<%# Eval("IsPrivateReader") %>' />
                             </itemtemplate>
                             <edititemtemplate>
                                 <asp:CheckBox ID="cbxPrivateReader" runat="server" checked='<%# Bind("IsPrivateReader") %>' />
                             </edititemtemplate>
                         </telerik:GridTemplateColumn>
                         <telerik:GridTemplateColumn headertext="Share" uniquename="SharedColumn">
                             <itemtemplate>
                                 <asp:CheckBox ID="cbxShare" runat="server" checked='<%# Eval("CanShare") %>' />
                             </itemtemplate>
                             <edititemtemplate>
                                 <asp:CheckBox ID="cbxShare" runat="server" checked='<%# Bind("CanShare") %>' />
                             </edititemtemplate>
                         </telerik:GridTemplateColumn>
                         <telerik:GridTemplateColumn AllowFiltering="true" HeaderText=" " 
                             Reorderable="true" ShowSortIcon="true" SortExpression="Name">
                             <ItemTemplate>
                                 <asp:ImageButton ID="btnDelete" runat="server" CausesValidation="False" 
                                     CommandName="DeleteSelected" ImageUrl="~/Images/Delete.gif" 
                                     OnClientClick="return GetUserConfirmForItemDelete(event);" 
                                     ToolTip="Delete Record" />
                             </ItemTemplate>
                         </telerik:GridTemplateColumn>
                     </Columns>
                     <EditFormSettings>
                         <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                         </EditColumn>
                     </EditFormSettings>
                 </MasterTableView>
                 <FilterMenu EnableTheming="True" Skin="WebBlue">
                     <CollapseAnimation Duration="200" Type="OutQuint" />
                 </FilterMenu>
             </telerik:RadGrid>

    This is my datasource:

    protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack)
                {
                    ViewState["DataSource"]  = new ArrayList();
                    SetInitialJavaScriptFunctions();
                }
            }
      
            private ArrayList DataSource { get { return (ArrayList)ViewState["DataSource"]; }


    private

     

     

    void BindDataGrid(string strSortExpression = "", SortDirection eSortDirection = SortDirection.Ascending)

     

    {

         dg.DataSource = DataSource;

         dg.DataBind();

    }


    What am I missing?

    Thanks
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 15 Mar 2012 Link to this post

    Hello Dan,

    I don't believe the automatic update feature of the RadGrid works without being bound to a DataSource control. So you'll need to perform the updates manually by handling the UpdateCommand, InsertCommand and DeleteCommand events and modify your datasource that way.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan Harvey
    Dan Harvey avatar
    67 posts
    Member since:
    Jul 2008

    Posted 15 Mar 2012 Link to this post

    Hey Kevin,

    My UpdateCommand is not firing.  Could you help me?  What I want is for when a user clicks on a checkbox in the row to be able to update that object bound to that row (so, checking the box i would like to set that property to true).

    I sample application would be appreciated.

    Thanks,
  5. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 19 Mar 2012 Link to this post

    Hello Dan,

    I have assembled a sample project demonstrating the desired functionality. You could try implementing it and if you have any related questions to contact us.

    Kind regards,
    Antonio Stoilkov
    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.
  6. Dan Harvey
    Dan Harvey avatar
    67 posts
    Member since:
    Jul 2008

    Posted 19 Mar 2012 Link to this post

    Oh great.  This was exactly what I was looking for.

    Thanks!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017