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

HIde items in EditForm

2 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Klein
Top achievements
Rank 1
Eric Klein asked on 09 Dec 2010, 10:38 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Dec 2010, 05:52 AM
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.
0
Eric Klein
Top achievements
Rank 1
answered on 10 Dec 2010, 03:17 PM
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.
Tags
Grid
Asked by
Eric Klein
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eric Klein
Top achievements
Rank 1
Share this question
or