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

Setting Enabled state of DropDownList after CheckedChanged Event

5 Answers 23 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Ida
Top achievements
Rank 1
Ida asked on 07 Jun 2017, 09:47 AM

Hi,

I have a RadGrid in Edit Mode, with a checkbox that when it is checked, a DropDownList's Enabled state should be True. When the checkbox is unchecked, the DropDownList's Enabled state should be False. Unfortunately I cannot get the Enabled state set after using the following code:

 

 

 

Public Sub RDPots_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
 
               If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
 
                   ' Checking the status of the Berried checkbox
                   Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
                   Dim chkBerried As CheckBox = CType(editedItem("Berried").Controls(0), CheckBox)
                   chkBerried.AutoPostBack = True
 
                   Dim dropdownBerriedStage As DropDownList = CType(editedItem("BerriedStage").Controls(0), DropDownList)
                   dropdownBerriedStage.AutoPostBack = True
 
                   AddHandler chkBerried.CheckedChanged, AddressOf Me.chkBerried_CheckedChanged
 
                   If bBerried Then
                       dropdownBerriedStage.Enabled = True
                   Else
                       dropdownBerriedStage.Enabled = False
                   End If
 
 
               End If
 
 
       End Sub
 
Sub chkBerried_CheckedChanged(sender As Object, e As System.EventArgs)
 
           Dim checkBerried As CheckBox = CType(sender, CheckBox)
           Dim eitem As GridEditableItem = DirectCast(checkBerried.NamingContainer, GridEditableItem)
 
           If checkBerried.Checked Then
               bBerried = True
           Else
               bBerried = False
           End If
 
       End Sub

5 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 09 Jun 2017, 08:34 AM
Hi Ida,

Once you have the GridEditableItem instance within the code-behind event handler, you can use the approach demonstrated in the following section:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ida
Top achievements
Rank 1
answered on 12 Jun 2017, 02:49 PM

Thank you for the advice Eyup, but unfortunately when the checkbox is checked/ticked, the new value of the checkbox state is not picked up on postback.

 

0
Eyup
Telerik team
answered on 14 Jun 2017, 10:45 AM
Hi,

Could you share which EditMode do you use? Then, we can prepare a sample RadGrid web site and send it to you.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ida
Top achievements
Rank 1
answered on 16 Jun 2017, 08:28 AM
<telerik:RadGrid ID="RDPots" runat="server" AutoGenerateEditColumn="True" GridLines="Horizontal" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#ecf3f4" BorderColor="#28899A" EditItemStyle-BackColor="#009999" EditItemStyle-Font-Bold="true" OnItemDataBound="RDPots_ItemDataBound" OnItemCreated="RDPots_ItemCreated" OnNeedDataSource="RDPots_NeedDataSource" CssClass="Radgrid" CommandItemDisplay="Top">
         <AlternatingItemStyle BackColor="#ECF3F4"></AlternatingItemStyle>
         <HeaderStyle BorderColor="#28899A" Font-Bold="True" Font-Size="12px" Font-Names="Verdana" />
            <MasterTableView EnableViewState="false">
                  <Columns>
                      <telerik:GridBoundColumn DataField="TripCode" FilterControlAltText="Filter TripCode column" HeaderText="Trip Code" SortExpression="TripCode" UniqueName="TripCode" ReadOnly="true"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="VessReg"  FilterControlAltText="Filter VessReg column" HeaderText="Vessel" SortExpression="VessReg" UniqueName="VessReg" ReadOnly="true"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="StringNumber"  FilterControlAltText="Filter StringNumber column" HeaderText="String Number" SortExpression="StringNumber" UniqueName="StringNumber" ReadOnly="true"></telerik:GridBoundColumn>
                      <telerik:GridDropDownColumn DataField="BaitType" HeaderText="Bait Type" ListTextField="nvcBaitTypeName" ListValueField="intBaitTypeID" UniqueName="BaitType" Visible="false" ColumnEditorID="BaitType" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                      <telerik:GridBoundColumn DataField="PotNumber"  FilterControlAltText="Filter PotNumber column" HeaderText="Pot Number" SortExpression="PotNumber" UniqueName="PotNumber" ReadOnly="true"></telerik:GridBoundColumn>
                      <telerik:GridDropDownColumn DataField="CatchType" HeaderText="Catch Type" ListTextField="Name" ListValueField="Code" UniqueName="CatchType" Visible="false" ColumnEditorID="CatchType" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                      <telerik:GridDropDownColumn DataField="Sex" HeaderText="Sex" ListTextField="SexDescription" ListValueField="SexCode" UniqueName="Sex" Visible="false" ColumnEditorID="Sex" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                      <telerik:GridBoundColumn DataField="SpeciesCode"  FilterControlAltText="Filter SpeciesCode column" HeaderText="Species" SortExpression="SpeciesCode" UniqueName="SpeciesCode" ReadOnly="true"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="TotalCount" HeaderText="Total Count" UniqueName="TotalCount" ColumnEditorID="TotalCount" Visible="false"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="MeasuredCount" HeaderText="Measured Count" UniqueName="MeasuredCount" ColumnEditorID="MeasuredCount" Visible="false"></telerik:GridBoundColumn>
                      <telerik:GridCheckBoxColumn DataField="VNotched" HeaderText="V Notched?" Visible="false" UniqueName="VNotched" ColumnEditorID="VNotched"></telerik:GridCheckBoxColumn>
                      <telerik:GridCheckBoxColumn DataField="Berried" HeaderText="Berried?" Visible="false" UniqueName="Berried" ColumnEditorID="Berried"></telerik:GridCheckBoxColumn>                      
                      <telerik:GridDropDownColumn DataField="BerriedStage" HeaderText="Berried Stage" ListTextField="BerriedStageName" ListValueField="BerriedStageID" UniqueName="BerriedStage" Visible="false" ColumnEditorID="BerriedStage" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                      <telerik:GridBoundColumn DataField="CarapaceLength" HeaderText="Carapace Length" UniqueName="CarapaceLength" ColumnEditorID="CarapaceLength" Visible="false"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="CarapaceWidth" HeaderText="Carapace Width" UniqueName="CarapaceWidth" ColumnEditorID="CarapaceWidth" Visible="false"></telerik:GridBoundColumn>
                      <telerik:GridCheckBoxColumn DataField="Tagged" HeaderText="Tagged?" Visible="false" UniqueName="Tagged" ColumnEditorID="Tagged"></telerik:GridCheckBoxColumn>
                      <telerik:GridDropDownColumn DataField="ShellCondition" HeaderText="Shell Condition" ListTextField="ShellConditionName" ListValueField="ShellConditionID" UniqueName="ShellCondition" Visible="false" ColumnEditorID="ShellCondition" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                      <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure you want to delete the selected row?" />
                   </Columns>
                 </MasterTableView>
             </telerik:RadGrid>

 

Here is the RadGrid that I am using. The DataField called Berried is the checkbox I wish to detect a changed state for. The DataField called BerriedStage is the dropdown that I wish to enable/disable when the Berried checkbox is checked/not checked.

0
Eyup
Telerik team
answered on 20 Jun 2017, 10:58 AM
Hi Ida,

I've created a sample RadGrid web site to demonstrate how you can achieve this requirement. Please run the attached application and let me know if it helps you.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownList
Asked by
Ida
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Ida
Top achievements
Rank 1
Share this question
or