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

GridcheckBox with ReadOnly=false is not working (unable to check/uncheck)

3 Answers 308 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 26 Jul 2010, 02:58 PM

GridcheckBox with ReadOnly=false is not working (unable to check/uncheck)

 I have a few GridCheckBoxColumn inside a RadGrid. I have the ReadOnly property set to false but i cannot edit any of the checkboxes, that is I can neither check or uncheck them.
 Anyone with any ideas as to why this is happening? Any comments/suggestions/ideas/correctiosn much appreciated as I'n new to the whole telerik markup.

Cheers,
Alan



</
telerik:RadToolBar>
    <telerik:RadGrid ID="RadGrid3" runat="server" OnNeedDataSource="TelerikGridOnNeedDatasource" 
        DataSourceID="dsActionProperties" PageSize="500" >
        <MasterTableView DataSourceID="dsActionProperties" AllowCustomSorting="True">
            <Columns>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Action Name" UniqueName="Name" SortExpression="Action Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ActionSourceID" HeaderText="Action Source" UniqueName="ActionSourceID" >
                </telerik:GridBoundColumn>                              
                <telerik:GridCheckBoxColumn DataField="IsStateChecked" DataType="System.Boolean" HeaderText="State Dependent"  UniqueName="IsStateDependent" ReadOnly="false">
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </telerik:GridCheckBoxColumn>                                                               
                <telerik:GridCheckBoxColumn DataField="IsTypeDependent" DataType="System.Boolean" HeaderText="Type Dependent" UniqueName="TypeDependent">
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </telerik:GridCheckBoxColumn>                                                                                               
                <telerik:GridCheckBoxColumn DataField="Enabled" DataType="System.Boolean" HeaderText="Enabled" UniqueName="Enabled" ReadOnly="false">
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </telerik:GridCheckBoxColumn>                                                               
            </Columns>                            
        </MasterTableView>
    </telerik:RadGrid><br />
    <asp:ObjectDataSource ID="dsActionProperties" runat="server"  OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetAllActions" TypeName="DataSources.ActionsDS">
    </asp:ObjectDataSource>

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Jul 2010, 06:11 AM
Hello Alan,

In browser mode, the check box in GridCheckBoxColumn is disabled, so that it acts as a read-only control. If you want to check/uncheck the CheckBox in browser mode, then use CheckBox inside GridTemplateColumn like below.

ASPX:
<telerik:GridTemplateColumn HeaderText="State Dependent">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" Checked='<%# Eval("IsStateChecked") %>' runat="server" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

Hope this helps you,
Princy.
0
Alan
Top achievements
Rank 1
answered on 27 Jul 2010, 03:18 PM
Hi Princy,

    This works like a charm. Thank you. Now I'm trying to use Ajax to register a change in the status of any of the checkboxes. I want to feed this change back to the Session variable in the code-behind file. 
    Any ideas/starters as how to do this?

    Once again comments/suggestions/ideas much appreciated and thanks again.

Alan
0
Princy
Top achievements
Rank 2
answered on 28 Jul 2010, 09:25 AM
Hello Alan,

Option #1:
One suggestion is adding CheckedChanged event to CheckBox and saving the corresponding value in in session from code behind and ajaxify the grid using AjaxManager/AjaxPanel.


Option #2:
Another option is invoking the ajaxRequest from client event and saving the values in session variable in AjaxManager_AjaxRequest server event.
For accomplishing this attach the onclick event to checkbox from code behid.
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
        string id = item.GetDataKeyValue("EmployeeID").ToString(); // get DataKeyvalue
        chk.Attributes.Add("onclick", "OnClick(this,'" + id + "');");
    }
}

Now in the client side, invoke the ajaxRequest in onclick handler.
function OnClick(chk, key) {
    var value = new Array()
    value[0] = chk.checked;
    value[1] = key
    var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
    ajaxManager.ajaxRequest(value); // ajaxRequest
}
 
Save the values in code behind:
protected void RadAjaxManager1_AjaxRequest1(object sender, AjaxRequestEventArgs e)
{
    string value = e.Argument;
    string[] array;
    array = value.Split(',');
    // Session["checked"] = array[0];  // save the values in session
    // Session["keyValue"] = array[1];
 }


Also make surethat you set the AjaxSettings accordingly.
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>



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