Binding ContextMenu into GridView

3 posts, 0 answers
  1. Mazdak
    Mazdak avatar
    30 posts
    Member since:
    Nov 2010

    Posted 30 Jan 2011 Link to this post

    I'm trying to integrate RadContextMenu into GridView , I'm ware of example which do this with RagGrid but I prefer to do it with normal gridview, I add this code into my TemplateField :

    <telerik:RadContextMenu ID="ChooseDesktopImage" runat="server"
                EnableRoundedCorners="true" EnableShadows="true" OnClientItemClicked="OpenTagging">
                <Targets>
                    <telerik:ContextMenuElementTarget ElementID="lblFileName" />
                </Targets>
                <Items>
                    <telerik:RadMenuItem Text="Tag" Value='<%# Bind("workspace_file_mapping_id")  %>' />
                </Items>
            </telerik:RadContextMenu>

    But I get compile error which says :

    The RadMenuItem control with a two-way databinding to field workspace_file_mapping_id must have an ID.

    Is that even possible to do what I want?

    Regards
    Mazdak
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Jan 2011 Link to this post

    Hello Mazdak,

    Try using Eval instead of Bind method. Here is a sample code.

    C#:
    <telerik:RadContextMenu ID="ChooseDesktopImage" runat="server" DataSourceID="SqlDataSource1"
               DataTextField="EmployeeID"
               EnableShadows="true">
       <Targets>
              <telerik:ContextMenuElementTarget ElementID="lblFileName" />
       </Targets>
       <Items>
               <telerik:RadMenuItem Text="Tag" Value='<%# Bind("EmployeeID") %> ' />
        </Items>
    </telerik:RadContextMenu>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mazdak
    Mazdak avatar
    30 posts
    Member since:
    Nov 2010

    Posted 31 Jan 2011 Link to this post

    Hi,

    Thanks, this solved the error, now the page run and GridView bind , but when I right click on filename label no context menu displayed, the page has this javascript error when it loads:

    'null' is null or not an object.

    Here is my GridView code:
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            onrowdeleting="GridView_RowDeleting" AllowPaging="True" 
            onpageindexchanging="GridView_PageIndexChanging" onrowcommand="GridView_RowCommand"
            CellPadding="4" ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField DataField="workspace_file_mapping_id" Visible="False" />
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# GetWorkspacename( Eval("workspace_id") ) %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="File">
                    <ItemTemplate>
                        <asp:Label ID="lblFileName" runat="server" Text='<%# GetFilename( Eval("file_id") ) %>'></asp:Label>
                        <telerik:RadContextMenu ID="ChooseTagging" runat="server"
                            EnableRoundedCorners="true" EnableShadows="true" OnClientItemClicked="OpenTagging"
                        <Targets
                            <telerik:ContextMenuElementTarget ElementID="lblFileName" /> 
                        </Targets
                        <Items
                            <telerik:RadMenuItem Text="Tag" Value='<%# Eval("workspace_file_mapping_id")  %>' /> 
                        </Items
                    </telerik:RadContextMenu>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Username">
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# GetUsername(Eval("user_id")) %>'></asp:Label>                    
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>                
                    <ItemTemplate>                   
                             <asp:LinkButton ID="LinkButton2" OnClientClick="if (confirm("Are you sure you want to delete this workspace file mapping?")) return true;else return false;"  runat="server" CausesValidation="False" 
                                CommandName="Delete" CommandArgument='<%# Eval("workspace_file_mapping_id") %>' Text="Delete"></asp:LinkButton>                            
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>




Back to Top