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

Retaining checkbox selection server side on a radgrid using advanced data binding

3 Answers 356 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henry
Top achievements
Rank 1
Henry asked on 28 Jul 2014, 10:17 AM
Hi,

I was hoping to keep any ticked check boxes ticked when my radgrid rebinds. I found this tutorial: http://www.telerik.com/help/aspnet-ajax/grid-selecting-row-with-checkbox-server-side.html however my "onCheckedItem" events never fire, instead my "needDataSource" event is fired and that is the end of it (I verified this using debug mode and checkpoints). I'm assuming this is because I'm using advanced data binding unlike in the tutorial. I need to keep advanced data binding for features such as grid export. Also it's important the checkboxes are server side because I want to be able to build functions in c# which rely on what tick boxes are selected. Below is the code for my radgrid 

Let me know if you need any more code. Thanks in advance

[code]
​<telerik:RadGrid ID="batchGrid" runat="server"
AllowFilteringByColumn="True" AllowSorting="True"
CellSpacing="0" GridLines="None" OnNeedDataSource="batchGrid_NeedDataSource"
EnableViewState="False" AutoGenerateColumns="True" OnColumnCreated="batchGrid_ColumnCreated"
OnExportCellFormatting="batchGrid_ExportCellFormatting"><ExportSettings ExportOnlyData="true" HideStructureColumns="true" >
<Excel Format="Html"/>
 </ExportSettings> <ClientSettings AllowColumnsReorder="True" EnablePostBackOnRowClick="false" >
 <Selecting AllowRowSelect="false"/>
 <Resizing AllowResizeToFit="true" />
 </ClientSettings> <MasterTableView NoMasterRecordsText="No batch found containing this part, with the current filters">
<Columns>
 <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false" Reorderable="false" >
 <ItemTemplate>
 <asp:CheckBox ID="MyCheckBox" runat="server" OnCheckedChanged="ToggleRowSelection" AutoPostBack="true" />
 </ItemTemplate>
 <HeaderTemplate>
 <asp:CheckBox ID="headerChkbox" runat="server" OnCheckedChanged="ToggleSelectedState" AutoPostBack="true" />
 </HeaderTemplate>
 </telerik:GridTemplateColumn>
 </Columns>
 <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
 <HeaderStyle Width="20px" />
 </RowIndicatorColumn>
 <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
 <HeaderStyle Width="20px" />
 </ExpandCollapseColumn>
 <EditFormSettings>
 <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
 </EditFormSettings>
 </MasterTableView> <FilterMenu EnableImageSprites="False" ></FilterMenu>
</telerik:RadGrid>
[/code]

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2014, 05:27 AM
Hi Henry,

I guess you want to persist your checkbox selected values on grid rebind. Please take a look at the following documentation:
Persisting CheckBox control state in GridTemplateColumn on rebind

Thanks,
Princy
0
Henry
Top achievements
Rank 1
answered on 29 Jul 2014, 09:11 AM
Hi Princy,

First of all thanks for getting back to me.

Currently I have EnableViewState="False", if I make it true (which your solution suggests I need to do) then my grid will only bound on the initial page load. So I added this to my page_load method:

if (IsPostBack)
{
    batchGrid.DataSource = GetDataTable();
}

The GetDataTable method definitely works fine because I use it in the "onNeedDataSource" without any problems. But with the above "fix" I get this error when I load a second column in my grid (columns are set to be automatically generated and tickboxes determine which data is gathered from a DB using a function which builds the SQL string).

Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

Do you have any ideas to get around this? Or perhaps another solution to my initial problem without using viewstate?

Kind regards

Henry



0
Accepted
Princy
Top achievements
Rank 2
answered on 31 Jul 2014, 10:06 AM
Hi Henry,

Please take a look at the following documentation for more help, when EnableViewState="False".
Optimizing ViewState usage
Rebind grid on command/postback event with EnableViewState = false

Thanks,
Princy
Tags
Grid
Asked by
Henry
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Henry
Top achievements
Rank 1
Share this question
or