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

Disable check box if already checked

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Najid Hanif
Top achievements
Rank 2
Najid Hanif asked on 15 Sep 2011, 08:49 PM
Hi, on my grid in edit mode, i would like to disable a check box if it is already checked so it can not be changed. How can I do this?

Thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Sep 2011, 05:57 AM
Hello Najid,

Take a look at my following thread where it discusses the similar scenario.
how to enable control on edit mode if check box is checked .

Thanks,
Princy.
0
Najid Hanif
Top achievements
Rank 2
answered on 19 Sep 2011, 07:39 PM
Hi I need a little more help on this. If I understand that code correctly, it will update a text box after a checkbox has been checked. Not exactly what I need to do. I need to disable the checkbox after it has been checked (only after the form has been saved/updated). My checkbox column is like this: Does it need to be a template column? Using the editor I tried to convert this column to a template column but that button is grayed out for this column.

<telerik:GridCheckBoxColumn DataField="MovedToBS" DataType="System.Boolean"
                            FilterControlAltText="Filter MovedToBS column" HeaderText="MovedToBS"
                            SortExpression="MovedToBS" UniqueName="MovedToBS">
 
 
    <FilterTemplate>
          <telerik:RadComboBox ID="MovedToBSFilter" runat="server" OnClientSelectedIndexChanged="MovedToBSFilterSelectedIndexChanged"
              SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("MovedToBS").CurrentFilterValue %>'
              Width="70px" DataSourceID="MovedToBSList" AppendDataBoundItems="true" OnItemDataBound="MovedToBSFilter_ItemDataBound">
              <Items>
                  <telerik:RadComboBoxItem Text="All"/>
              </Items>
          </telerik:RadComboBox>
          <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
 
              <script type="text/javascript">
                  function MovedToBSFilterSelectedIndexChanged(sender, args) {
                      var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                      var filterVal = args.get_item().get_value();
                      if (filterVal == "") {
                          tableView.filter("MovedToBS", filterVal, "NoFilter");
                      }
                      else if (filterVal == "1") {
                          tableView.filter("MovedToBS", "1", "EqualTo");
                      }
                      else if (filterVal == "0") {
                          tableView.filter("MovedToBS", "0", "EqualTo");
                      }
                  }
              </script>
 
          </telerik:RadScriptBlock>
      </FilterTemplate>
 
 
 
</telerik:GridCheckBoxColumn>
0
Maria Ilieva
Telerik team
answered on 21 Sep 2011, 04:07 PM
Hi Najid,

In this case it will be better if you are using TemplateColumn with checkbox in it. For example:
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemCreated="RadGrid1_ItemCreated">
           <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False">
               <Columns>
                   <telerik:GridTemplateColumn UniqueName="TempCheckBox">
                       <ItemTemplate>
                           <asp:CheckBox ID="CheckBox1" runat="server" />
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
                   . . .
                                 </Columns>
           </MasterTableView>
       </telerik:RadGrid>
CS:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
            chk.Attributes.Add("onclick", "test(" + chk.ClientID + ")");
 
        }
    }

JS:
<script type="text/javascript">
 
function test(cntrl)
 
{
   
    if(cntrl.checked)
    {  
    cntrl.disable();
    }
 
    else
    {
        cntrl.enable();
    }
 
    </script>


Give this a try and let me know if it helps.

Greetings,
Maria Ilieva
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
Tags
Grid
Asked by
Najid Hanif
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Najid Hanif
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or