简体   繁体   中英

How to use batch edit for checkbox column in radgrid?

I've checkbox column in my Radgrid. I'm using Batch edit to edit the values. In the itemtemplate for the column, I need to display 'Yes'/'No' values based on the data from database which is 1 or 0 and when the cell is clicked, checkbox should be unchecked if the value is 'no' and viceversa.

When I'm clicking on the itemtemplate cell for edit, checkbox is coming as checked always in edititemtemplate(even if the value is No in itemtemplate), which is not expected.

<telerik:GridTemplateColumn HeaderText="Locked?" UniqueName="Locked" DataField="LockedInd" SortExpression="LockedInd">                   
                   <ItemTemplate>
                       <asp:Label ID="lblLocked" runat="server" Text='<%# Convert.ToBoolean(Eval("LockedInd")) ? "Yes" : "No" %>' />
                   </ItemTemplate>
                   <EditItemTemplate>
                       <asp:CheckBox runat="server" ID="chkLock" Checked='<%# Bind("LockedInd")%>'/>
                   </EditItemTemplate>
               </telerik:GridTemplateColumn>

Per Telerik's documentation

When the EditMode is set to Batch, data binding expressions are not allowed in the EditItemTemplate. RadGrid will (attempt to) set the editor's value with JavaScript.

Telerik will try to automatically determine what the value of the control being edited should be, so a checked checkbox in the item template would reasonably translate to a checked check box in the edit template however a label does not intuitively convert to a checkbox.

The simplest solution without using other column types or controls would be to hook the clientSettings-ClientEvents-OnBatchEditOpened event and parse the value of the label to set the checkbox accordingly.

My assumption that may explain your always true behavior... because your data stored in a label is text/string based, when telerik attempts to assign the value of the label (using javascript as noted above), a non-null/non-empty string of "1" or "0" is truthy and results in a checked checkbox each time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM