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

bind readonly property of a textbox in edit item template

1 Answer 499 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harry
Top achievements
Rank 1
Harry asked on 21 May 2014, 10:05 PM
Hi,

I am trying to to bind the readonly property of a text box in Edit Item Template of rad grid as below, But it is not working. Please help me to achieve this.

<telerik:GridTemplateColumn DataField="invAmountToPay" SortExpression="invAmountToPay" UniqueName="invAmountToPay"
                                    Aggregate="Sum" DataType="System.Decimal" HeaderText="Amount To Pay"
                                    FooterAggregateFormatString="{0:N}" AllowFiltering="false">
                                    <EditItemTemplate>
                                        <asp:TextBox runat="server"
                                            ID="AmountToPayTextBox"
                                            Width="90px"
                                            Style="text-align: right"
                                            Text='<%# Eval("invAmountToPay","{0:N}") %>' 
                                            ReadOnly='<%# Eval("isReadOnly") %>'                                          
                                            DataFormatString="{0:N}">
                                        </asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="AmountToPayLabel" runat="server" Text='<%# Eval("invAmountToPay","{0:N}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <HeaderStyle Width="100px" />
                                    <FooterStyle HorizontalAlign="Right" />
                                    <ItemStyle HorizontalAlign="Right" ForeColor="#0000ff" />
                                </telerik:GridTemplateColumn>





1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 May 2014, 05:32 AM
Hi Harry,

I guess you want to set the TextBox ReadOnly property based on another columns value. You can do it from aspx or server side as follows:

ASPX:
<EditItemTemplate>
    <asp:TextBox runat="server" ID="AmountToPayTextBox" Text='<%# Eval("invAmountToPay") %>' ReadOnly='<%#Eval("isReadOnly") %>'>
    </asp:TextBox>
</EditItemTemplate>

        OR

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditableItem && e.Item.IsInEditMode)
  {
    GridEditableItem editItem = (GridEditableItem)e.Item;
    string isReadOnly = ((DataRowView)e.Item.DataItem)["isReadOnly"].ToString();
    TextBox txtAmountToPay = (TextBox)editItem.FindControl("AmountToPayTextBox");
    txtAmountToPay.ReadOnly = Convert.ToBoolean(isReadOnly);
  }
}

Thanks,
Princy
Tags
Grid
Asked by
Harry
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or