4

I have a RadGrid which has a column like:

<telerik:GridTemplateColumn HeaderText="Car" >
    <ItemTemplate>
        <asp:Label ID="MakeLabel" runat="Server" Text='<%# Eval("Make") %> />
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="MakeTextBox" runat="Server" Text='<%# Bind("Make") %> />
    </EditItemTemplate>
</telerik:GridTemplateColumn >

and I'm wanting to set it up so that this column will allow input when inserting new values but won't when updating values.

Can someone please make a suggestion?

BigJim
  • 411
  • 6
  • 20

3 Answers3

3

I think the simplest way for you to accomplish this would be by adding an InsertItemTemplate and changing the EditItemTemplate to a Label.

<telerik:GridTemplateColumn HeaderText="Car" >
    <ItemTemplate>
        <asp:Label ID="MakeLabel" runat="Server" Text='<%# Eval("Make") %> />
    </ItemTemplate>
    <InsertItemTemplate>
        <asp:TextBox ID="MakeTextBox" runat="Server" Text='<%# Bind("Make") %> />
    </InsertItemTemplate>
    <EditItemTemplate>
        <asp:Label ID="MakeLabel" runat="Server" Text='<%# Eval("Make") %> />
    </EditItemTemplate>
</telerik:GridTemplateColumn >

This way, you don't have to mess around with it in your code behind.

Michael Richardson
  • 4,213
  • 2
  • 31
  • 48
0

I found your question when searching for a solution to this myself. I was able to cobble something together that works; don't know if it's the best way, but I tend to go with what works. ;-)

Set your GridTemplateColumn as ReadOnly="true", and be sure to give it a UniqueName property. Then create a PreRender handler for the grid that does this:

    Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
        For Each column As GridColumn In RadGrid.Columns
            If column.UniqueName = "MyName" Then
                If column.Owner.IsItemInserted Then
                    CType(column, GridTemplateColumn).ReadOnly = False 
                Else
                    CType(column, GridTemplateColumn).ReadOnly = True
                End If
                Exit For
            End If
        Next

        RadGrid1.Rebind()
    End Sub
RobLinx
  • 117
  • 3
  • 11
0

I ended up going with in the Page_Load

myTextBox.Enabled = Parent.NamingContainer is GridEditFormInsertItem;

This is in the usercontrol used for updates/inserts of data

BigJim
  • 411
  • 6
  • 20