HIde items in EditForm

3 posts, 1 answers
  1. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 09 Dec 2010 Link to this post

    I have a rad grid and when the user select edit or insert it opens the EditForm using a Template.  Depending on who the user is there are two items that I would like to either show or hide.  Here is a sample of the code.
      <rad:RadGrid ID="gridClients" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" EnableAJAX="True" EnableAJAXLoadingTemplate="True" GridLines="None" LoadingTemplateTransparency="50" ShowStatusBar="True" Skin="Windows" Width="98%" AllowFilteringByColumn="True" PageSize="25" DataBound="gridClients_ItemDataBound" OnUpdateCommand="gridClients_UpdateCommand" OnInsertCommand="gridClients_InsertCommand" OnDeleteCommand="gridClients_DeleteCommand">
    ...
    <EditFormSettings EditFormType="Template" UserControlName="ClientGrid" >
      <EditColumn UniqueName="EditCommandColumn"></EditColumn>
      <FormTemplate>
         <table cellpadding="2" cellspacing="0" border="0" width="100%">
           <tr id="SpecialInstructRow" runat="server" visible="false">
             <td>
                <label for="SpecialInstuct">Billing Notes:</label>
                <asp:TextBox ID="SpecialInstructTextBox" runat="server" Text='<%# Bind("SpecialInstructions")  %>' TextMode="MultiLine" ></asp:TextBox>
              </td>
           </tr>
      
    ...
    </table>


    As you can see I have the table row visible set to false.  How can I change this when the user hits the edit or insert button on the grid, based on the user who is loged in?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Dec 2010 Link to this post

    Hello Eric,

    Give a try with the following code snippet .

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditFormItem editItem = e.Item as GridEditFormItem;
                if ()// your condition
                    ((System.Web.UI.WebControls.TableCell)((editItem.EditFormCell as GridEditFormItem.EditFormTableCell))).Controls[0].Visible = false;
                else
                    ((System.Web.UI.WebControls.TableCell)((editItem.EditFormCell as GridEditFormItem.EditFormTableCell))).Controls[0].Visible = true;
            }
        }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 10 Dec 2010 Link to this post

    Thanks that is it.  I was looking for an onediting or oninserting event, but this works great.  Even better if you use the .FindControl do you can seacrh be name.
Back to Top