I have tried several possibilities, none of which seem to work. I need the "Variable" column to be editable on an Insert, but not editable on an edit. The "Value" column has to be editable in both cases.
The first and third possibilities both leave the "Variable" column editable always. The middle leaves the "Variable" column never editable. What am I missing?
BTW the examples on how to do the first possibility leave out exactly how to set the readonly property.
protected void SubstitutionVariables_OnItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
if (e.Item.OwnerTableView.IsItemInserted)
{
Telerik.Web.UI.RadTextBox tb = (Telerik.Web.UI.RadTextBox)e.Item.FindControl("rtbSubstVarEdit");
tb.Visible = true;
tb.ReadOnly = false;
tb.Enabled = true;
}
else
{
Telerik.Web.UI.RadTextBox tb = (Telerik.Web.UI.RadTextBox)e.Item.FindControl("rtbSubstVarEdit");
tb.Visible = true;
tb.ReadOnly = true;
tb.Enabled = false;
}
}
}
protected void SubstitutionVariables_OnColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
if (e.Column.UniqueName == "Variable")
{
GridBoundColumn Column = (GridBoundColumn)e.Column;
Column.ReadOnly = !e.OwnerTableView.IsItemInserted;
}
}
<telerik:RadGrid ID="RadGrid1" runat="server"
AllowMultiRowSelection="true"
AllowAutomaticDeletes="false"
AllowAutomaticInserts="true"
AllowAutomaticUpdates="true"
AllowFilteringByColumn="false"
AllowMultiRowEdit="false"
AllowPaging="false"
AllowSorting="false"
OnNeedDataSource="SubstitutionVariables_OnNeedDataSource"
OnColumnCreated="SubstitutionVariables_OnColumnCreated"
OnItemCreated="SubstitutionVariables_OnItemCreated"
OnUpdateCommand="SubstitutionVariables_OnUpdate"
OnInsertCommand="SubstitutionVariables_OnInsert"
OnDeleteCommand="SubstitutionVariables_OnDelete">
<ClientSettings><Selecting AllowRowSelect="true" /></ClientSettings>
<MasterTableView InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="InPlace" >
<Columns>
<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" />
<telerik:GridTemplateColumn DataField="Variable" HeaderText="Variable" UniqueName="SubstitutionVariable"
Visible="false" >
<ItemTemplate>
<asp:Label ID="lblSubstVar" runat="server" ClientIDMode="Static"
Width="150px" />
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadTextBox ID="rtbSubstVarEdit" runat="server" ClientIDMode="Static"
Width="150px" />
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="rtbSubstVarEdit" runat="server" ClientIDMode="Static" ReadOnly="true"
Width="150px" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Value" HeaderText="Value" UniqueName="SubstitutionValue"
Visible="false">
<ItemTemplate>
<asp:Label ID="lblSubstValue" runat="server" ClientIDMode="Static"
Width="150px" />
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadTextBox ID="rtbSubstValueEdit" runat="server" ClientIDMode="Static"
Width="150px" />
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="rtbSubstValueEdit" runat="server" ClientIDMode="Static"
Width="150px" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemTemplate>
</CommandItemTemplate>
</MasterTableView>
</telerik:RadGrid>
The first and third possibilities both leave the "Variable" column editable always. The middle leaves the "Variable" column never editable. What am I missing?
BTW the examples on how to do the first possibility leave out exactly how to set the readonly property.
protected void SubstitutionVariables_OnItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
if (e.Item.OwnerTableView.IsItemInserted)
{
Telerik.Web.UI.RadTextBox tb = (Telerik.Web.UI.RadTextBox)e.Item.FindControl("rtbSubstVarEdit");
tb.Visible = true;
tb.ReadOnly = false;
tb.Enabled = true;
}
else
{
Telerik.Web.UI.RadTextBox tb = (Telerik.Web.UI.RadTextBox)e.Item.FindControl("rtbSubstVarEdit");
tb.Visible = true;
tb.ReadOnly = true;
tb.Enabled = false;
}
}
}
protected void SubstitutionVariables_OnColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
if (e.Column.UniqueName == "Variable")
{
GridBoundColumn Column = (GridBoundColumn)e.Column;
Column.ReadOnly = !e.OwnerTableView.IsItemInserted;
}
}
<telerik:RadGrid ID="RadGrid1" runat="server"
AllowMultiRowSelection="true"
AllowAutomaticDeletes="false"
AllowAutomaticInserts="true"
AllowAutomaticUpdates="true"
AllowFilteringByColumn="false"
AllowMultiRowEdit="false"
AllowPaging="false"
AllowSorting="false"
OnNeedDataSource="SubstitutionVariables_OnNeedDataSource"
OnColumnCreated="SubstitutionVariables_OnColumnCreated"
OnItemCreated="SubstitutionVariables_OnItemCreated"
OnUpdateCommand="SubstitutionVariables_OnUpdate"
OnInsertCommand="SubstitutionVariables_OnInsert"
OnDeleteCommand="SubstitutionVariables_OnDelete">
<ClientSettings><Selecting AllowRowSelect="true" /></ClientSettings>
<MasterTableView InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="InPlace" >
<Columns>
<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" />
<telerik:GridTemplateColumn DataField="Variable" HeaderText="Variable" UniqueName="SubstitutionVariable"
Visible="false" >
<ItemTemplate>
<asp:Label ID="lblSubstVar" runat="server" ClientIDMode="Static"
Width="150px" />
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadTextBox ID="rtbSubstVarEdit" runat="server" ClientIDMode="Static"
Width="150px" />
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="rtbSubstVarEdit" runat="server" ClientIDMode="Static" ReadOnly="true"
Width="150px" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Value" HeaderText="Value" UniqueName="SubstitutionValue"
Visible="false">
<ItemTemplate>
<asp:Label ID="lblSubstValue" runat="server" ClientIDMode="Static"
Width="150px" />
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadTextBox ID="rtbSubstValueEdit" runat="server" ClientIDMode="Static"
Width="150px" />
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="rtbSubstValueEdit" runat="server" ClientIDMode="Static"
Width="150px" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemTemplate>
</CommandItemTemplate>
</MasterTableView>
</telerik:RadGrid>