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

Readonly Column in RadGrid

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
New User
Top achievements
Rank 1
New User asked on 08 Dec 2010, 12:14 AM
I have a radgrid with a readonly column named Status.  After my validation completes I need to change the value of the column if there is an error.  I'm having problems changing the value. Any suggestions would be helpful.

if (errorCount > 0)
{               
    TableCell statusCell = item["STATUS"];
    (statusCell.Controls[0] as TextBox).Text = "Error";
    (statusCell.Controls[0] as TextBox).BackColor = System.Drawing.Color.Red;
}
<telerik:RadGrid ID="rdDeposits" AllowSorting="False" AllowPaging="False" runat="server"
                            AutoGenerateColumns="False" AllowAutomaticInserts="False" OnPreRender="rdDeposits_PreRender" 
                            AllowAutomaticDeletes="False" Skin="Web20" OnNeedDataSource="rdDeposits_NeedDataSource"
                             OnItemDataBound="rdDeposits_ItemDataBound" GridLines="Horizontal"  OnItemCommand="rdDeposits_ItemCommand" 
                             OnItemCreated="rdDeposits_ItemCreated" OnDeleteCommand="rdDeposits_ItemDeleted"
                            AllowMultiRowEdit="False" Width="738px" Height="360px">
                            <MasterTableView ShowFooter="true" DataKeyNames="ESCROW_ACCOUNT_DEPOSIT_ID" CommandItemDisplay="Top" EditMode="InPlace" TableLayout="Fixed">
                                <CommandItemTemplate>
                                    <div style="padding: 5px 5px;">
                                        <asp:Button ID="btnAdd" CommandName="InitInsert" Text="Add Transaction" runat="server" />
                                    </div>
                                </CommandItemTemplate>
                                <Columns> 
                                    <telerik:GridBoundColumn DataField="ESCROW_ACCOUNT_DEPOSIT_ID" UniqueName="ESCROW_ACCOUNT_DEPOSIT_ID"
                                        ReadOnly="true" Visible="false">
                                    </telerik:GridBoundColumn>                                                                                               
                                    <telerik:GridDropDownColumn DataField="DEPOSIT_TRANS_TYPE_ID" HeaderText="Type" UniqueName="DEPOSIT_TRANS_TYPE_SDESC" 
                                        ListTextField="DEPOSIT_TRANS_TYPE_SDESC" ListValueField ="DEPOSIT_TRANS_TYPE_ID"
                                        DropDownControlType="DropDownList"  ColumnEditorID="GridDropDownColumnEditor1">
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="110px" />
                                        <FooterStyle HorizontalAlign="Right" Font-Bold="true" /> 
                                    </telerik:GridDropDownColumn>                                                      
                                    <telerik:GridBoundColumn DataField="EXPECTED_DATE" HeaderText="Expected Date" UniqueName="EXPECTED_DATE"
                                        ReadOnly="true">
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="90px" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="EXPECTED_AMOUNT" HeaderText="Expected Amount"
                                        UniqueName="EXPECTED_AMOUNT" ReadOnly="true">
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="100px" />
                                        <ItemStyle HorizontalAlign="Right"/>
                                        <FooterStyle HorizontalAlign="Right" Font-Bold="true" /> 
                                    </telerik:GridBoundColumn>
                                    <telerik:GridDateTimeColumn DataField="ACTUAL_DATE" HeaderText="Actual Date" UniqueName="ACTUAL_DATE"
                                        DataType="System.DateTime" ColumnEditorID="GridDateTimeColumnEditor">
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="100px" />                                        
                                    </telerik:GridDateTimeColumn>
                                    <telerik:GridNumericColumn DataField="ACTUAL_AMOUNT" HeaderText="Actual Amount" UniqueName="ACTUAL_AMOUNT"
                                         NumericType="Currency" Resizable="False" MaxLength="8" DataType="System.Decimal"  >
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="100px"  />
                                        <ItemStyle HorizontalAlign="Center" />   
                                        <FooterStyle HorizontalAlign="Right" Font-Bold="true" />                                                                                                                                                                                                                                                                
                                    </telerik:GridNumericColumn>                                                                                                  
                                    <telerik:GridBoundColumn DataField="STATUS" HeaderText="Status" UniqueName="STATUS"
                                         ReadOnly="true">
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="90px" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </telerik:GridBoundColumn>                                                                    
                                    <telerik:GridButtonColumn ButtonType="ImageButton" Text="Delete"
                                         ImageUrl='../Images/deleteX.GIF' CommandName="Delete" UniqueName="Delete">
                                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="15px" />
                                    </telerik:GridButtonColumn>
                                    <telerik:GridBoundColumn DataField="EXPECTED_TRANSACTION_IND" UniqueName="EXPECTED_TRANSACTION_IND" ReadOnly="true"
                                       Visible="false" ForceExtractValue="Always" >
                                    </telerik:GridBoundColumn>                                       
                                </Columns>                                                                                             
                            </MasterTableView>
                            <SelectedItemStyle BackColor="#F8C320" />
                            <ClientSettings EnableRowHoverStyle="true">
                                <Selecting AllowRowSelect="true" />
                                <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" />
                            </ClientSettings>            
                        </telerik:RadGrid>


Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 08 Dec 2010, 06:21 AM
Hello,

Since you have set the column's ReadOnly property as 'True', it will not rendered as TextBox in edit mode. So try the following code snippet to achieve your requirement.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            TableCell statusCell = item["STATUS"];
            statusCell.Text = "Error";
            statusCell.BackColor = System.Drawing.Color.Red;
        }
    }

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