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

How to fix column EditItemTemplate with contextmenu hide columns ?

7 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eslam
Top achievements
Rank 1
Eslam asked on 10 Dec 2013, 03:58 PM
hi,
please how can set columns EditItemTemplate when user hide columns by context menu.
EditItemTemplate always visible inline at bottom above command item.
but when user hide column the whole column visible set to false , i need to hide only item template ..

thanx.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2013, 10:01 AM
Hi Eslam,

When hiding a GridTemplateColumn using HeaderContextMenu, only its ItemTemplate is hidden. Below is a sample code that i tried, please have a look. If this doesn't help, please provide your code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" EnableHeaderContextMenu="true">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>          
            <telerik:GridTemplateColumn HeaderText="EmployeeID">
                <ItemTemplate>
                    <asp:Label Text='<%# Bind("EmployeeID") %>' runat="server" ID="Label1" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="EditTextBox" runat="server" Text='<%#Bind("EmployeeID") %>'></asp:TextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Princy
0
Eslam
Top achievements
Rank 1
answered on 12 Dec 2013, 09:39 AM
hi Princy,

thank you for replay.

i forget to tell what exactly happen ,, sorry

as you say only ItemTemplate is hidden.but for example if you navigate to any page all of GridTemplateColumn wil hidden.

my code exactly as your code sir..


Thanks,
eslam

0
Princy
Top achievements
Rank 2
answered on 12 Dec 2013, 10:34 AM
Hi Eslam,

I couldn't replicate the issue at my end. Can you provide your full code snippet so as to help you.

Thanks,
Princy
0
Eslam
Top achievements
Rank 1
answered on 12 Dec 2013, 02:50 PM
Hi Princy,

thanks for replay,,

using batch update and using item databound event to add attributes to controls.
code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1"  OnNeedDataSource="RadGrid1_NeedDataSource"  Width="100%" ShowStatusBar="True" ClientSettings-KeyboardNavigationSettings-AllowSubmitOnEnter="false"
    AllowSorting="true"  GridLines="None" AllowPaging="true" PageSize="5" runat="server" ClientSettings-Resizing-AllowColumnResize="true"
    AutoGenerateColumns="False" AllowAutomaticInserts="True" OnPreRender="RadGrid1_PreRender" OnDeleteCommand="RadGrid1_DeleteCommand"
        OnItemDataBound="RadGrid1_ItemDataBound" AllowAutomaticDeletes="false"  EnableViewState="true" GroupingEnabled="false">
 
<HeaderContextMenu EnableEmbeddedBaseStylesheet="true" style="direction:rtl; text-align:right;"></HeaderContextMenu>
 
    <MasterTableView TableLayout="Auto" DataKeyNames="Invoice_Item_Id" EditMode="InPlace" EnableViewState="true"
        ClientDataKeyNames="Invoice_Item_Id" CommandItemDisplay="Bottom" Dir="RTL"  EnableHeaderContextMenu="true"
         NoMasterRecordsText="لا يوجد بيانات" >
         
        
        <PagerStyle AlwaysVisible="true" PagerTextFormat="{4} عدد الصفح {1} ,  عدد الاصناف  {5}" PageSizeLabelText="   عدد الاصناف فى الصفحة   " Mode="NextPrevAndNumeric" PageSizeControlType="RadDropDownList" PageSizes="10,20,30,50,100,150,200,300,400,500,600,700,800,900,1000"  />
 
        <HeaderStyle  VerticalAlign="Middle" HorizontalAlign="Center"/>
         
        <CommandItemTemplate>
            <div style="height: 30px;  float: left;">
                 <asp:Image ID="imgDeleteInvoice" runat="server" ImageUrl="../../../Shared/Images/ContentPage/deleteAll.png"
                    AlternateText="حذف الفاتورة" ToolTip="حذف الفاتورة" Height="24px" Style="cursor: pointer;
                    margin: 2px 5px 0px 0px; float:left;" onclick="DeleteInvoice2();"></asp:Image>
                <asp:Image ID="imgCancelChanges" runat="server" ImageUrl="../../../Shared/Images/ContentPage/cancel.gif"
                    AlternateText="إلغاء التعديلات" ToolTip="إلغاء التعديلات" Height="24px" Style="cursor: pointer;
                    margin: 2px 5px 0px 0px; float:left;" onclick="CancelChanges2();"></asp:Image>
                <asp:Image ID="imgProcessChanges" runat="server" ImageUrl="../../../Shared/Images/ContentPage/ok.gif"
                    AlternateText="حفظ" ToolTip="حفظ" Height="24px" Style="cursor: pointer;
                    margin: 2px 5px 0px 0px; float:left;" onclick="ProcessChanges2('RadGrid1');"></asp:Image>
 
            </div>
            <div style="height:30px; float:right; padding-top:5px;">
            </div>
 
            <div style="height:30px; padding-top:5px; float:left; ">
                مجموع الصفحة=
                <asp:Label ID="pageTotal" runat="server"   Width="75px"> </asp:Label>
                     
                 إجمالى الفاتورة=
                <asp:Label ID="AllTotal" runat="server"  Width="90px"> </asp:Label>
            </div>
            </CommandItemTemplate>
         
        <EditItemStyle Height="15px" HorizontalAlign="center" VerticalAlign="Middle" />
        <Columns>
            
             <telerik:GridTemplateColumn UniqueName="RowNumber"  HeaderText="م" HeaderStyle-BackColor="#669999" HeaderStyle-Width="1.4%" ItemStyle-HorizontalAlign="Center"  FooterStyle-Width="1.4%" ItemStyle-Width="1.4%"  ItemStyle-VerticalAlign="Middle" >
                 <ItemStyle BackColor="#bfcdd0" />
                 <HeaderStyle Height="1236" BackColor="#bfcdd0" />
            <EditItemTemplate><asp:Label ID="Label8" runat="server" Text="" Width="50px" BackColor="#bfcdd0" Height="22px"/>
                    <asp:Button ID="Button12" Text="I" runat="server" OnClientClick="openWinContentTemplate(); return false;" Visible="false" />
                     
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn  UniqueName="Invoice_Code" SortExpression="Invoice_Code" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="رقم الفاتورة" HeaderStyle-Width="10%"  ItemStyle-Height="12px" Visible="false">
                <ItemTemplate>
                    <%# Eval("Id") %>
                </ItemTemplate>
                   <EditItemTemplate>
                       <telerik:RadTextBox Width="100px" runat="server"  ID="txtInvoiceIdEdit" Enabled="false">  
                       </telerik:RadTextBox>
                   </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn  UniqueName="Invoice_Date" SortExpression="Invoice_Date" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="تاريخ الفاتورة" HeaderStyle-Width="8%"  ItemStyle-Height="12px" Visible="false">
                <ItemTemplate>
                    <%# Convert.ToDateTime(Eval("InvoiceData")).ToString("d") %>
                </ItemTemplate>
                   <EditItemTemplate>
                        <telerik:RadTextBox runat="server" Width="85px" ID="txtInvoiceDateEdit" Enabled="false" />
                   </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn  UniqueName="Invoice_Item_Id" SortExpression="Invoice_Item_Id" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="كود الصنف" HeaderStyle-Width="9%" FooterStyle-Width="10%" ItemStyle-Width="9%"  ItemStyle-Height="12px">
                <ItemTemplate>
                    <asp:Label ID="lblItemId" runat="server" Text='<%# Eval("Invoice_Item_Id") %>' ></asp:Label>
                    <asp:TextBox ID="txtItemID"   runat="server" Text='<%# Bind("Invoice_Item_Id") %>' Width="95%"
                        Style="display: none"></asp:TextBox>
                   
                </ItemTemplate>
                   <EditItemTemplate>
                       <asp:Button ID="Button3" Text="I" runat="server" OnClientClick="openWinContentTemplate(); return false;"  Visible="true"/>
                       <telerik:RadNumericTextBox Width="100%" runat="server" EmptyMessage="كود الصنف" TabIndex="1"  AutoPostBack="true" OnTextChanged="txtItemIdEdit_TextChanged"  ID="txtItemIdEdit"  MinValue="1"  AllowOutOfRangeAutoCorrect="true" InvalidStyleDuration="900" >  
                       </telerik:RadNumericTextBox>
                   </EditItemTemplate>
            </telerik:GridTemplateColumn>
          
            <telerik:GridTemplateColumn UniqueName="Invoice_Item_Name" SortExpression="itemName" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="اسم الصنف" HeaderStyle-Width="10%" FooterStyle-Width="10%" ItemStyle-Width="10%"  ItemStyle-Height="10px" >
                <ItemTemplate>
                    <%# Eval("itemName") %>
                </ItemTemplate>
                   <EditItemTemplate>
                        <telerik:RadTextBox runat="server" Width="100%" ID="txtItemNameEdit" Enabled="false" EmptyMessage="اسم الصنف" />
                   </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn UniqueName="Invoice_Item_MainPrice" SortExpression="Price" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="سعر الصنف" HeaderStyle-Width="7%" FooterStyle-Width="6%" ItemStyle-Width="7%"  ItemStyle-Height="10px" >
                <ItemTemplate>
                    <%# Eval("Price") %>
                    <asp:Label runat="server" Text='<%# Eval("Price") %>' ID="lblMainPrice" Visible="false" />
                    <asp:Label runat="server" Text='<%# Eval("PriceChange") %>' ID="lblPriceChange" Visible="false" />
                </ItemTemplate>
                   <EditItemTemplate>
                        <asp:TextBox runat="server" Width="100%" ID="txtItemMainPrice" Enabled="false" TabIndex="100" />
                  </EditItemTemplate>
                 
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn UniqueName="Invoice_Item_Price" SortExpression="Invoice_Item_Price" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="سعر البيع" HeaderStyle-Width="7%" FooterStyle-Width="7%" ItemStyle-Width="8%"  ItemStyle-Height="10px">
                <ItemTemplate>
                    <asp:Label ID="lblItemPrice" runat="server" Text='<%# Eval("Invoice_Item_Price") %>' ></asp:Label>
                    <asp:TextBox ID="txtItemPrice"   runat="server" Text='<%# Bind("Invoice_Item_Price") %>' Width="95%"
                        Style="display: none"></asp:TextBox>
                     </ItemTemplate>
                   <EditItemTemplate>
                            <telerik:RadNumericTextBox runat="server"  Width="100%" ID="txtItemPriceEdit" MinValue="1" EmptyMessage="سعر البيع"  AllowOutOfRangeAutoCorrect="true" InvalidStyleDuration="900" />  
                   </EditItemTemplate>
                
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn UniqueName="Invoice_Item_Quantity" SortExpression="Invoice_Item_Quantity" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="الكمية" HeaderStyle-Width="6%" FooterStyle-Width="6%" ItemStyle-Width="6.5%"  ItemStyle-Height="10px" >
                <ItemTemplate>
                    <asp:Label ID="lblItemQuantity" runat="server" Text='<%# Eval("Invoice_Item_Quantity") %>' Width="100%"></asp:Label>
                    <asp:TextBox ID="txtItemQuantity" runat="server" Text='<%# Bind("Invoice_Item_Quantity") %>' Width="100%"
                        Style="display: none"></asp:TextBox>
                </ItemTemplate>
                   <EditItemTemplate>
                        <telerik:RadNumericTextBox runat="server" Width="100%" DisabledStyle-HorizontalAlign="Right"  EmptyMessage="الكمية" TabIndex="2" AutoPostBack="true"  OnTextChanged="txtItemQuantityEdit_TextChanged"  ID="txtItemQuantityEdit"  MinValue="1"  MaxLength="9"  AllowOutOfRangeAutoCorrect="true" InvalidStyleDuration="900" />  
                   </EditItemTemplate>
                    
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn UniqueName="Invoice_Item_Total" SortExpression="total" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                HeaderText="الإجمالى" DataField="total" HeaderStyle-Width="9%"  FooterStyle-Width="9%" ItemStyle-Width="9%"  ItemStyle-Height="10px"
                FooterStyle-HorizontalAlign="Center" FooterStyle-VerticalAlign="Middle">
                <ItemTemplate>
                    <asp:Label ID="txtItemTotal" runat="server" Text='<%# Bind("total","{0:0.##}") %>'></asp:Label>
                </ItemTemplate>
                   <EditItemTemplate>
                       <telerik:RadTextBox runat="server" ID="RadTextBox1" Width="100%" Enabled="false"  EmptyMessage="الاجمالى"/>
                   </EditItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn UniqueName="TestHide" HeaderText="HideCol" Display="false" HeaderStyle-Width="2%" ItemStyle-HorizontalAlign="Center"  FooterStyle-Width="1%" ItemStyle-Width="1.5%"  ItemStyle-VerticalAlign="Middle" >
                <ItemTemplate><%# Eval("Id") %></ItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn HeaderStyle-Width="9.5%"  FooterStyle-Width="9.5%" ItemStyle-Width="9.5%" UniqueName="DeleteCol">
                <EditItemTemplate>
                      <div style="width:197px;float:right;">
                         <telerik:RadButton ID="btnInsert" runat="server" TabIndex="3" Text="إضافة" OnClick="btnInsert_Click" UseSubmitBehavior="false"/>
                         <telerik:RadButton ID="btnSearchInvoiceItem" runat="server" TabIndex="4" Text="بحث" OnClick="btnSearchInvoiceItem_Click" UseSubmitBehavior="false"/>                             
                      </div>
                </EditItemTemplate>
                <ItemTemplate>
                    <div style="width:97px;float:left;">
                        <telerik:RadButton ID="RadButton1" CommandName="Delete" runat="server" Text="حذف" UseSubmitBehavior="false" OnClientClicking="DeleteConfirmation"></telerik:RadButton>
                    </div>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
 
        </Columns>
        
    </MasterTableView>
   
     <ClientSettings >
          
         <Resizing AllowColumnResize="false" />
         <KeyboardNavigationSettings AllowSubmitOnEnter="false" />
         <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="false"  ScrollHeight="150">
        </Scrolling>
        <Selecting AllowRowSelect="true" />
        <ClientEvents OnRowCreated="RowCreated2" OnRowClick="RowClick2" OnCommand="RadGrid1_Command2"  OnMasterTableViewCreated="GridCreated"
            OnRowDestroying="RowDestroying2" OnCellSelected="CellChangeCheck" OnGridCreated="RowCount2" ></ClientEvents><%--OnGridCreated="RowCount"--%>
    </ClientSettings>
     </telerik:RadGrid>

code behind :
protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.IsItemInserted = true;
            RadGrid1.MasterTableView.InsertItemDisplay = GridInsertItemDisplay.Bottom;
        }
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            // alot of code
        }
 
 
 protected void Page_Load(object sender, EventArgs e)
        {
            RadGrid1.HeaderContextMenu.ItemCreated += new     Telerik.Web.UI.RadMenuEventHandler(HeaderContextMenu_ItemCreated);
        }
 
protected void HeaderContextMenu_ItemCreated(object sender, Telerik.Web.UI.RadMenuEventArgs e)
        {
switch (e.Item.Value)
            {
                case "SortAsc":
                    e.Item.Text = "الترتيب تصاعدياُ";
                    break;
                case "SortDesc":
                    e.Item.Text = "الترتيب تنازلياٌ";
                    break;
                case "SortNone":
                    e.Item.Text = "إلغاء الترتيب";
                    break;
                case "GroupBy":
                    e.Item.Text = "مجموعة بـ";
                    break;
                case "UnGroupBy":
                    e.Item.Text = "بدون مجموعة";
                    break;
                case "ColumnsContainer":
                    e.Item.Text = "إظهار/إخفاء حقل";
                    break;
                case "FilterMenuParent":
                    e.Item.Text = "التصفية";
                    break;
}

thank you.
eslam
0
Eslam
Top achievements
Rank 1
answered on 15 Dec 2013, 03:38 PM
Hi Princy

any updates !!!?

thank you
eslam
0
Viktor Tachev
Telerik team
answered on 19 Dec 2013, 07:41 AM
Hello Eslam,

There was an issue when hiding columns with Display=false in RadGrid with Batch editing enabled in older versions of the controls. The issue has been already resolved and the fix is included in the latest version (currently 2013.3.1114).

Would you try upgrading to the latest version of the controls and see if there will be any change? If the issue persists I would ask you to send your full markup with the code-behind. This would enable us to try replicating the problem locally and provide an appropriate solution.

Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Eslam
Top achievements
Rank 1
answered on 22 Dec 2013, 01:58 PM
hi Viktor,,

thanx for replay .. I really appreciate it

i will try thank you
Tags
Grid
Asked by
Eslam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eslam
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or