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

Unable to update underlying datasource

4 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan Harvey
Top achievements
Rank 2
Dan Harvey asked on 15 Mar 2012, 01:03 AM
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

4 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 15 Mar 2012, 01:48 PM
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.
0
Dan Harvey
Top achievements
Rank 2
answered on 15 Mar 2012, 04:10 PM
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,
0
Antonio Stoilkov
Telerik team
answered on 19 Mar 2012, 12:02 PM
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.
0
Dan Harvey
Top achievements
Rank 2
answered on 19 Mar 2012, 05:02 PM
Oh great.  This was exactly what I was looking for.

Thanks!
Tags
Grid
Asked by
Dan Harvey
Top achievements
Rank 2
Answers by
Kevin
Top achievements
Rank 2
Dan Harvey
Top achievements
Rank 2
Antonio Stoilkov
Telerik team
Share this question
or