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

Change ReadOnly to Edit in a EditableForm with a radcombobox

5 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laurent
Top achievements
Rank 2
Laurent asked on 12 Oct 2012, 10:51 AM
Hello,
I have a problem on the edit form.
My rule is to perform calculations in the edit form with special use.
I have a radcombobox (Billing % or Amount) to select 2 status. The first status (Amount) set the field of the percentage in readonly in the form and editable the field "Amount Value to be invoiced". When I switch to set "Percentage", the field percentage change to be editable and set the field "Amount Value to be invoiced" to ReadOnly.
But I haven't solution to do this action in the edit form.
Can you help me? Do you have a exemple?

When the user input data in the field automatically there is complex calcul in code behind. Actualy I have GridNumericColumn linked to GridNumericColumnEditor with this code :
<telerik:GridNumericColumnEditor runat="server" ID="GridColumnEditor_Percentage">
    <NumericTextBox Culture="en-US" DisplayText="" LabelCssClass="" LabelWidth="64px"
        AutoPostBack="true" MinValue="0" OnTextChanged="RadNumericTextBoxGrid_TextChanged">
        <NumberFormat ZeroPattern="n" DecimalDigits="0" />
    </NumericTextBox>
</telerik:GridNumericColumnEditor>
It's the good solution to manage my GridNumericColumn to do my calcul? I can't use the GridCalculatedColumn because I have a lot of parameters.
Thanks you for your help.
Best Regards
Laurent

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Oct 2012, 11:10 AM
Hi,

I suppose you are using dropdowncolumn and boundcolumns. Here is the sample code that I tried to make the columns readonly based on the selected value of the dropdowncolumn.
aspx:
<telerik:RadGrid ID="RadGrid1" AutoGenerateEditColumn="true" DataSourceID="SqlDataSource2" runat="server" AutoGenerateColumns="false" onitemcreated="RadGrid1_ItemCreated">
 <MasterTableView>
   <Columns>
    <telerik:GridDropDownColumn UniqueName="drop" DropDownControlType="RadComboBox" DataSourceID="SqlDataSource2" ListTextField="FirstName" ListValueField="FirstName"></telerik:GridDropDownColumn>
    <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="LastName" UniqueName="Name"></telerik:GridBoundColumn>
   </Columns>
 </MasterTableView>
</telerik:RadGrid>
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        RadComboBox combo = (RadComboBox)item["drop"].Controls[0];
        combo.AutoPostBack = true;
        combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
    }
}
 
void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    GridEditableItem item = (GridEditableItem)combo.NamingContainer;
         
    TextBox txt1 = (TextBox)item["FirstName"].Controls[0];
    TextBox txt2 = (TextBox)item["Name"].Controls[0];
    if (combo.SelectedItem.Text == "Sachin")
    {
        txt1.ReadOnly = true;
        txt2.ReadOnly = false;
    }
    else
    {
        txt2.ReadOnly = true;
        txt1.ReadOnly = false;
    }
}

Thanks,
Princy.
0
Laurent
Top achievements
Rank 2
answered on 12 Oct 2012, 12:07 PM
Thanks you for your answer.
Actualy I use this solution with a radcombobox.
This is the code but the grid no change when I have selected a other status. It's lite different like your but the idea is the same...no?

RadGrid :
<telerik:RadGrid AutoGenerateColumns="False" ID="gridBillingEvents" OnNeedDataSource="gridBillingEvents_NeedDataSource"
    AllowSorting="True" PageSize="20" ShowFooter="True" AllowPaging="True" runat="server"
    OnItemCreated="gridBillingEvents_ItemCreated" OnInsertCommand="gridBillingEvents_InsertCommand"
    OnDeleteCommand="gridBillingEvents_DeleteCommand" OnUpdateCommand="gridBillingEvents_UpdateCommand"
    OnItemDataBound="gridBillingEvents_ItemDataBound" GridLines="None" Width="95%"
    Skin="Windows7" ShowStatusBar="True" EnableLinqExpressions="False" CellSpacing="0"
    AllowMultiRowEdit="True" GroupingEnabled="False" OnItemCommand="gridBillingEvents_ItemCommand"
    DataMember="BillingEvent" OnSelectedIndexChanged="gridBillingEvents_SelectedIndexChanged">
    <GroupingSettings CaseSensitive="false" />
    <MasterTableView Width="100%" EditMode="InPlace" ShowFooter="True" DataMember="BillingEvent"
        DataKeyNames="h960_upgradebillingeventid, h960_billingdescription, h960_billingperoramount"
        CommandItemDisplay="Top">
        <CommandItemSettings AddNewRecordText="Add New Billing Event" RefreshText="Refresh" />
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
        </RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="false">
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridDateTimeColumn DataField="h960_billingdate" HeaderStyle-Width="8%" HeaderText="Billing Date"
                UniqueName="Billingbillingdate" AllowFiltering="False" DataFormatString="{0 : dd-MMM-yyyy}">
                <HeaderStyle Width="8%" />
            </telerik:GridDateTimeColumn>
            <telerik:GridTemplateColumn HeaderText="Billing % or Amount" UniqueName="BillingPercentOrAmount">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="cbPercentOrAmount" Height="8%" runat="server" Skin="WebBlue"
                        DataTextField="Value" DataValueField="key" DataSourceID="odsPercentOrAmount"
                        AutoPostBack="true" SelectedValue='<%# Bind("h960_billingperoramount")%>' NoWrap="True"
                        OnSelectedIndexChanged="cbPercentOrAmount_SelectedIndexChanged">
                    </telerik:RadComboBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <%# GetLabelOfBillingOrPercentFromValue(Eval("h960_billingperoramount"))%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Billing Type" UniqueName="BillingType">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="cbBillingType" Height="8%" runat="server" Skin="WebBlue"
                        DataTextField="Value" DataValueField="Key" DataSourceID="odsBillingDescription"
                        SelectedValue='<%# Bind("h960_billingdescription")%>'>
                    </telerik:RadComboBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <%# GetLabelOfBillingDescriptionFromValue(Eval("h960_billingdescription"))%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridNumericColumn DataField="h960_msnquantity" HeaderStyle-Width="10%" HeaderText="MSN Quantity"
                ShowFilterIcon="true" UniqueName="Billingmsnquantity" ColumnEditorID="GridColumnEditor_MsnQuantity">
                <HeaderStyle Width="150px" />
            </telerik:GridNumericColumn>
            <telerik:GridNumericColumn DataField="h960_percentage" HeaderStyle-Width="15%" HeaderText="Percentage of value to be invoiced"
                ShowFilterIcon="true" UniqueName="Billingpercentage" ColumnEditorID="GridColumnEditor_Percentage">
                <HeaderStyle Width="150px" />
            </telerik:GridNumericColumn>
            <telerik:GridNumericColumn DataField="h960_amount" HeaderStyle-Width="15%" HeaderText="Amount value to be Invoiced"
                ShowFilterIcon="true" UniqueName="Billingamount" ColumnEditorID="GridColumnEditor_Amount">
                <HeaderStyle Width="15%" />
            </telerik:GridNumericColumn>
            <telerik:GridTemplateColumn HeaderText="Usage">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="cbUsages" Width="50px" Height="15%" runat="server" Skin="WebBlue"
                        DataTextField="h960_name" DataValueField="IdString" DataSourceID="odsUsages"
                        SelectedValue='<%# Bind("h960_upgradeusageid")%>'>
                    </telerik:RadComboBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <%# GetLabelOfUsageFromValue(Eval("h960_upgradeusageid"))%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridNumericColumn DataField="h960_paymentcustomerview" HeaderStyle-Width="15%"
                HeaderText="Customer view payment amount (take into account DP)" ShowFilterIcon="true"
                UniqueName="BillingDueNetAmount" ColumnEditorID="GridColumnEditor_DueNetAmount">
                <HeaderStyle Width="150px" />
            </telerik:GridNumericColumn>
            <telerik:GridTemplateColumn UniqueName="BillingbtnMSN" HeaderStyle-Width="5%">
                <ItemTemplate>
                    <asp:Button ID="EditMSN" runat="server" Text="MSN Selection" />
                </ItemTemplate>
                <HeaderStyle Width="5%" />
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="h960_msnallocation" HeaderStyle-Width="10%" ReadOnly="true"
                HeaderText="MSN Allocation" ShowFilterIcon="true" UniqueName="Billingmsnallocation">
                <HeaderStyle Width="150px" />
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                HeaderStyle-Width="8%" EditText="Edit" CancelText="Cancel" UpdateText="Update"
                InsertText="Insert">
                <HeaderStyle Width="8%" />
                <ItemStyle CssClass="MyImageButton" />
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn ConfirmText="Confirm deletion of Billing Event ?" ConfirmDialogType="RadWindow"
                HeaderStyle-Width="25px" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete"
                Text="Delete" UniqueName="Delete">
                <HeaderStyle Width="25px" />
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <ClientSettings EnablePostBackOnRowClick="true">
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" />
    </ClientSettings>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>
<telerik:GridNumericColumnEditor runat="server" ID="GridColumnEditor_MsnQuantity">
</telerik:GridNumericColumnEditor>
<telerik:GridNumericColumnEditor runat="server" ID="GridColumnEditor_Percentage">
    <NumericTextBox Culture="en-US" DisplayText="" LabelCssClass="" LabelWidth="64px"
        AutoPostBack="true" MinValue="0" OnTextChanged="RadNumericTextBoxGrid_TextChanged">
        <NumberFormat ZeroPattern="n" DecimalDigits="0" />
    </NumericTextBox>
</telerik:GridNumericColumnEditor>
<telerik:GridNumericColumnEditor runat="server" ID="GridColumnEditor_Amount">
    <NumericTextBox Culture="en-US" DisplayText="" LabelCssClass="" LabelWidth="64px"
        AutoPostBack="true" MinValue="0" OnTextChanged="RadNumericTextBoxGrid_TextChanged">
        <NumberFormat ZeroPattern="n" DecimalDigits="0" />
    </NumericTextBox>
</telerik:GridNumericColumnEditor>
<telerik:GridNumericColumnEditor runat="server" ID="GridColumnEditor_DueNetAmount">
    <NumericTextBox Culture="en-US" DisplayText="" LabelCssClass="" LabelWidth="64px"
        AutoPostBack="true" MinValue="0" OnTextChanged="RadNumericTextBoxGrid_TextChanged">
        <NumberFormat ZeroPattern="n" DecimalDigits="0" />
    </NumericTextBox>
</telerik:GridNumericColumnEditor>

Code Behind :
protected void gridBillingEvents_ItemDataBound(object sender, GridItemEventArgs e)
{
    try
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            Button btnMSN = (Button)item["BillingbtnMSN"].Controls[1];
 
            if (!e.Item.IsInEditMode)
            {
                int BillingType = Convert.ToInt16(item.GetDataKeyValue("h960_billingdescription"));
 
                if (BillingType == 1)
                    btnMSN.Visible = false;
            }
        }
        if (e.Item.IsInEditMode)
        {
            GridEditableItem oeditModeRow = (GridEditableItem)e.Item;
 
            GridEditManager oeditManager = oeditModeRow.EditManager;
 
            GridNumericColumnEditor GridNumericMSNQuantity = (GridNumericColumnEditor)oeditManager.GetColumnEditor("Billingmsnquantity");
 
            GridNumericColumnEditor GridNumericAmount = (GridNumericColumnEditor)oeditManager.GetColumnEditor("Billingamount");
 
            GridNumericColumnEditor GridNumericPerc = (GridNumericColumnEditor)oeditManager.GetColumnEditor("Billingpercentage");
 
            GridNumericColumnEditor GridNumericDueNetAmount = (GridNumericColumnEditor)oeditManager.GetColumnEditor("BillingDueNetAmount");
 
            //Hide button MSN Allocation
            Button btnMSN = (Button)oeditModeRow["BillingbtnMSN"].Controls[1];
            btnMSN.Visible = false;
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
 
protected void RadNumericTextBoxGrid_TextChanged(object sender, EventArgs e)
{
    //Complex Calcul
}
 
protected void cbPercentOrAmount_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    GridEditableItem item = (GridEditableItem)combo.NamingContainer;
 
    RadNumericTextBox colPerc = (RadNumericTextBox)item["Billingpercentage"].Controls[0];
    RadNumericTextBox colAmount = (RadNumericTextBox)item["Billingamount"].Controls[0];
 
    if (e.Value == "2")
    {
        if (colPerc != null)
            colPerc.ReadOnly = false;
 
        if (colAmount != null)
            colAmount.ReadOnly = true;
    }
    else
    {
        if (colPerc != null)
            colPerc.ReadOnly = true;
 
        if (colAmount != null)
            colAmount.ReadOnly = false;
    }
}

Regards
Laurent
0
Laurent
Top achievements
Rank 2
answered on 12 Oct 2012, 03:52 PM
As for me, I misspoke ...
The functionality to switch on the radcombobox works....but it visually displays the field as an input field and I would like to have as a readonly field like on the picture...
Thanks you
Regards
Laurent
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Oct 2012, 06:48 AM
Hi,

Try modifying the if condition as follows.

C#:
if (combo.SelectedItem.Text == "2")
{
    txt1.Visible = false;
    item["Billingpercentage"].Controls.Add(lbl);
    lbl.Text = txt1.Text;
    lbl.ID = "lbl1";
    txt2.ReadOnly = false;
}
else
{
    txt2.Visible = false;
    item["Billingamount"].Controls.Add(lbl1);
    lbl1.Text = txt2.Text;
    lbl1.ID = "lbl2";
}

Hope this helps.

Regards,
Princy.
0
Laurent
Top achievements
Rank 2
answered on 09 Nov 2012, 03:12 PM
Thanks Princy
Tags
Grid
Asked by
Laurent
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Laurent
Top achievements
Rank 2
Share this question
or