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

Edit item template readonly

5 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 21 Oct 2008, 03:56 PM
I have a price field in my grid which is an item template column and the item template and the edit template are both radnumeric textboxes. As part of my URL, I have a querystring telling me if the price is yes(editable), readonly(only show on grid but not in edit form) or no(dont show anywhere).
Here is the aspx:
 <telerik:GridTemplateColumn HeaderText="Package Price" UniqueName="NumericPrice" AllowFiltering="false">
<ItemTemplate>
        <telerik:RadNumericTextBox ID="inGridPkgPrice" runat="server"  Price='<%# Eval("packageprice") %>'  
Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "packageprice") %>'  
Width="125px"  OnTextChanged="RadNumericInlineGridTextChanged" AutoPostBack= "true">  
        </telerik:RadNumericTextBox>
</ItemTemplate>
 <EditItemTemplate>
     <telerik:RadNumericTextBox ID="inFormPkgPrice" runat="server"  Price='<%# Eval("packageprice") %>'  
Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "packageprice") %>'  
Width="125px"   OnTextChanged="RadNumericDefaultPackageTextChanged">  
    <ClientEvents OnLoad="PriceBoxLoad"  />
    </telerik:RadNumericTextBox>
</EditItemTemplate>

I have it inline editable in the grid,and if if is readonly, I was able to make the item template price .readonly = true, and just put a tooltip saying it is readonly so they dont try to edit it. Here is that code which works fine:
protected void usersGrid_PreRender(object sender, EventArgs e)
{

        foreach (GridDataItem item in usersGrid.Items)
        {
            if (Request.QueryString["price"] == "readonly")
            {
                RadNumericTextBox txtboxPrice = (RadNumericTextBox)item["NumericPrice"].FindControl("inGridPkgPrice");
                txtboxPrice.ReadOnly = true;
                txtboxPrice.ToolTip = "This field is readonly";
            }
        }
}

My question is, since the edititem is a radnumerictextbox, I just want to make it not visible in the edit form if is is readonly but don't know how or where.
Where would I put the code to make it not visible in the insert/edit form and what would that code be?

Thanks

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Oct 2008, 06:24 AM
Hello Laura,

To hide the RadNumericTextBox in the TemplateColumn you jus have to make a slight change in the code you have implemented as shown.
cs:
protected void usersGrid_PreRender(object sender, EventArgs e) 
 
        foreach (GridDataItem item in usersGrid.Items) 
        { 
            if (Request.QueryString["price"] == "readonly") 
            { 
                RadNumericTextBox txtboxPrice = (RadNumericTextBox)item["NumericPrice"].FindControl("inGridPkgPrice"); 
                txtboxPrice.Visible = false
                 
            } 
        } 

To hide the RadNumericTextBox in the EditItemTemplate of the TemplateColumn (in EditMode), you can try the following code.
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
          if (Request.QueryString["price"] == "readonly") 
            { 
            RadNumericTextBox txtboxPrice = (RadNumericTextBox)item["NumericPrice"].FindControl("inFormPkgPrice"); 
            txtboxPrice.Visible = false
 
            } 
        }        
    } 

Thanks
Princy.
0
Vlad
Telerik team
answered on 22 Oct 2008, 06:41 AM
Hi Laura,

Generally you do not need to loop on all items to make the control not Visible or ReadOnly. You can set this for the entire column using Visible column property. You can do this for example in Page_Load:

GridTemplateColumn column = (GridTemplateColumn)RadGrid1.MasterTableView.GetColumnSafe("NumericPrice");
column.Visible = Request.QueryString["price"] == "readonly";

Other possible approach for GridTemplateColumn is to set EditItemTemplate to null conditionally:

GridTemplateColumn column = (GridTemplateColumn)RadGrid1.MasterTableView.GetColumnSafe("NumericPrice");
if(Request.QueryString["price"] == "readonly")
{
    column.EditItemTemplate = null;
}

With our upcoming Q3 release we will introduce ReadOnly property for GridTemplateColumn.

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Laura
Top achievements
Rank 1
answered on 22 Oct 2008, 02:16 PM
Thanks for the reply Princy. As always, you give me good insight into the coding. One point is that in the code you gave me, you did not set item, so I got an error that item did not exist, so I added this line to resolve this problem.
  GridEditableItem item = e.Item as GridEditableItem;

Just thought I'd put this here in case anyone else tries this solution.

Ok, so now the price does not show in the edit form, but the headertext "Package Price" still shows. How can I get rid of the header text when i hide the field?

Thanks again,
Laura

0
Laura
Top achievements
Rank 1
answered on 22 Oct 2008, 02:31 PM
Thank you for the reply Vlad. I put this code into my page_load:
GridTemplateColumn column = (GridTemplateColumn)usersGrid.MasterTableView.GetColumnSafe("NumericPrice");
if(Request.QueryString["price"] == "readonly")
{
    column.EditItemTemplate = null;
}


and it still shows the NumericPrice column in the edit form.

That's great that you are adding readonly property for the gridtemplatecolumn. When is this expected to be released, and since I am fairly new to Telerik, and never upgraded to a newer version, how do I find out when a new release is out, and how do I find out how to upgrade?

Thanks
0
Sebastian
Telerik team
answered on 27 Oct 2008, 08:29 AM
Hello Laura,

The Q3 2008 release of RadControls for ASP.NET AJAX is scheduled by the end of the next week. You can check the 'News' section on our site or subscribe to the RSS feed there in order to be alerted when the new version of the ASP.NET AJAX suite is already a fact.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vlad
Telerik team
Laura
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or