title: Telerik RadGrid (using Batch Edit) Hide / Disable Column Based on Another Column's Value
body: <p>I'm trying to get RadGrid to conditionally hide or disable a field when it is in edit mode based on the value of another field.</p>
  
  <p>I have been able to get this to work when the grid displays the list of items, but once the grid enters edit mode, the columns display ... </p>
  
  <p>I am using OnItemDataBound to successfully conditionally display during the initial load, but setting the items when the user clicks a row to get it into batch mode is not working. </p>
  
  <p>Note: PValue and CValue and in GridTemplateColumns, as is CardStatus. </p>
  
  <pre><code>public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
      {
  foreach (GridDataItem item in RadGrid1.Items)
         {
            string BoundColumnValue = item["CardStatus"].Text; // accessing    GridBoundColumn value using ColumnUniqueName
              string BoundColumnValue2 = item["CValue"].Text;
              TextBox txtbx = (TextBox)item.FindControl("CardStatus");
              Label numlb = (Label)item.FindControl("CardValue");
  
              if (txtbx.Text.Equals("True"))
              {
                  txtbx.ForeColor = Color.Red;
  
                  numlb.Enabled = false;
                  numlb.BackColor = Color.Yellow;
                  numlb.ForeColor = Color.Red;
                 //Just testing to see if it would evaluate
              }
              else
              {
                  txtbx.ForeColor = Color.Beige;
              }
              //string TemplateColumnValue = lb.Text;// accessing Label Text.
          }
  
          foreach (GridEditableItem item in RadGrid1.EditItems)
          {
              string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
              string BoundColumnValue2 = item["CValue"].Text;
              TextBox txtbx = (TextBox)item.FindControl("CardStatus");
              if (txtbx.Text.Equals("True"))
              {
                  txtbx.ForeColor = Color.Red;
  
                  //numTxt.BackColor = Color.Yellow;
                  //numTxt.ForeColor = Color.Red;
              }
              else
              {
                  txtbx.ForeColor = Color.Beige;
              }
  }
  }
  </code></pre>
  
  <p>I just need to be able to selectively prevent data entry in a column</p>
  
  <p>The ASPX source is below:</p>
  
  <pre><code>&lt;telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="true" Height="930px" DataSourceID="SqlDataSource4" CellSpacing="0" GridLines="None" Width="640px" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated" OnBatchEditCommand="RadGrid1_BatchEditCommand1"  Skin="WebBlue"&gt;
                          &lt;ClientSettings&gt;
                              &lt;Scrolling AllowScroll="True" UseStaticHeaders="True" /&gt;
                          &lt;/ClientSettings&gt;
                          &lt;MasterTableView AutoGenerateColumns="False" EditMode="Batch" Width="620px" CommandItemDisplay="TopAndBottom" DataSourceID="SqlDataSource4" DataKeyNames="CountKey"&gt;
                              &lt;CommandItemSettings ExportToPdfText="Export to PDF" ShowSaveChangesButton="true" ShowRefreshButton="false" ShowAddNewRecordButton="false"&gt;&lt;/CommandItemSettings&gt;
                              &lt;BatchEditingSettings OpenEditingEvent="Click"  EditType="Row"  /&gt;
  
                              &lt;RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"&gt;
                                  &lt;HeaderStyle Width="20px"&gt;&lt;/HeaderStyle&gt;
                              &lt;/RowIndicatorColumn&gt;
  
                              &lt;ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"&gt;
                                  &lt;HeaderStyle Width="20px"&gt;&lt;/HeaderStyle&gt;
                              &lt;/ExpandCollapseColumn&gt;
  
                              &lt;EditFormSettings&gt;
                                  &lt;EditColumn FilterControlAltText="Filter EditCommandColumn column"&gt;&lt;/EditColumn&gt;
                              &lt;/EditFormSettings&gt;
  
                              &lt;PagerStyle PageSizeControlType="RadComboBox"&gt;&lt;/PagerStyle&gt;
                              &lt;Columns&gt;
                                  &lt;telerik:GridBoundColumn DataField="Pcolumn" ItemStyle-Width="75px" ReadOnly="true" Visible="false" DataType="System.Int32" FilterControlAltText="Filter Pcolumn column" HeaderText="Pcolumn" SortExpression="Pcolumn" UniqueName="Pcolumn"&gt;
                                  &lt;/telerik:GridBoundColumn&gt;
                                  &lt;telerik:GridBoundColumn DataField="Row" ReadOnly="true" Visible="false" DataType="System.Int32" FilterControlAltText="Filter Row column" HeaderText="Row" SortExpression="Row" UniqueName="Row"&gt;
                                  &lt;/telerik:GridBoundColumn&gt;
                                  &lt;telerik:GridTemplateColumn ColumnEditorID="PValue" HeaderText="Pattern" DataField="PValue" UniqueName="PValue" ItemStyle-Width="75px" HeaderStyle-Width="75px"&gt;
  
                                      &lt;EditItemTemplate&gt;
                                          &lt;telerik:RadNumericTextBox ID="PValue" Width="50px" runat="server" MaxLength="1" MaxValue="9" NumberFormat-DecimalDigits="0" Text='&lt;%# Bind("PValue") %&gt;'&gt;&lt;/telerik:RadNumericTextBox&gt;
                                          &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="PValue"  ErrorMessage="&lt;br/&gt;Required (0-9) Only)!" SetFocusOnError="true"&gt;&lt;/asp:RequiredFieldValidator&gt;
                                      &lt;/EditItemTemplate&gt;
                                      &lt;ItemTemplate&gt;
                                          &lt;asp:Label ID="PValue" Width="50px" runat="server" Text='&lt;%# Bind("PValue") %&gt;'&gt;&lt;/asp:Label&gt;
                                      &lt;/ItemTemplate&gt;
  
                                  &lt;/telerik:GridTemplateColumn&gt;
  
                                  &lt;telerik:GridTemplateColumn ColumnEditorID="CValue" DataField="CValue" HeaderText="Card" UniqueName="CValue" ItemStyle-Width="75px" HeaderStyle-Width="75px"&gt;
  
                                      &lt;EditItemTemplate&gt;
  
                                          &lt;telerik:RadNumericTextBox ID="CValue" Width="50px" AllowOutOfRangeAutoCorrect="false"  runat="server" MaxLength="1" MaxValue="1" NumberFormat-DecimalDigits="0" Text='&lt;%# Bind("CValue") %&gt;'&gt;&lt;/telerik:RadNumericTextBox&gt;
                                          &lt;asp:RequiredFieldValidator runat="server" ControlToValidate="CValue" ErrorMessage="&lt;br /&gt;Required (0-1 Only)!" SetFocusOnError="true"&gt;&lt;/asp:RequiredFieldValidator&gt;
                                      &lt;/EditItemTemplate&gt;
                                      &lt;ItemTemplate&gt;
                                          &lt;asp:Label ID="CValue" Width="50px" runat="server" Text='&lt;%# Bind("CValue") %&gt;'&gt;&lt;/asp:Label&gt;
                                      &lt;/ItemTemplate&gt;
  
                                  &lt;/telerik:GridTemplateColumn&gt;
                                  &lt;telerik:GridBoundColumn DataField="DateEdited" ReadOnly="true" Visible="false" DataType="System.DateTime" FilterControlAltText="Filter DateEdited column" HeaderText="DateEdited" SortExpression="DateEdited" UniqueName="DateEdited"&gt;
                                  &lt;/telerik:GridBoundColumn&gt;
                                  &lt;telerik:GridTemplateColumn UniqueName="CardStatus" DataField="CardStatus" ItemStyle-Width="50px" HeaderStyle-Width="50px"&gt;
                                  &lt;ItemTemplate&gt;
                                &lt;asp:TextBox ID="CardStatus" Width="10px"  runat="server" Text='&lt;%# Bind("CardStatus") %&gt;'&gt;&lt;/asp:TextBox&gt;           
                                  &lt;/ItemTemplate&gt;
                                      &lt;EditItemTemplate&gt;
        &lt;asp:TextBox ID="CardStatus" Width="10px"  runat="server" Text='&lt;%# Bind("CardStatus") %&gt;'&gt;&lt;/asp:TextBox&gt;           
  
                                      &lt;/EditItemTemplate&gt;
  
                              &lt;/telerik:GridTemplateColumn&gt;
  
                              &lt;/Columns&gt;
  
                          &lt;/MasterTableView&gt;
  
                          &lt;PagerStyle PageSizeControlType="RadComboBox"&gt;&lt;/PagerStyle&gt;
  
                          &lt;FilterMenu EnableImageSprites="False"&gt;&lt;/FilterMenu&gt;
  &lt;/telerik:RadGrid&gt;
  </code></pre>
  
  <p>Any help / workarounds would be appreciated ... again, "just" need to prevent editing in the CValue column when the CardStatus value is true (bit field) ... using batch mode (using another solution isn't an option now). </p>
  
  <p>Thanks</p>
  
  <p>Larry</p>