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

radcontextmenu Inside RadMenuItem record databind

6 Answers 131 Views
Menu
This is a migrated thread and some comments may be shown as answers.
mohamed
Top achievements
Rank 1
mohamed asked on 03 Sep 2012, 07:06 AM
I want bind record in radmenuitem through server side take from data base ,
And also i want find in page load ,

  
<MasterTableView  AllowFilteringByColumn="true" IsFilterItemExpanded="false" HeaderStyle-Width="200px" ItemStyle-Width="200px" CommandItemDisplay="Top" DataKeyNames="lid"  ClientDataKeyNames="lid" Width="100%">
           <CommandItemTemplate>           
               <div style="padding: 5px 0px 5px 7px; text-align: left; font-weight:bold;">
               <span class="gridHeaderTitle">
                   <i><telerik:RadCodeBlock ID="RadCodeBlock2" runat="server"><%= Resources.People.People_List %></telerik:RadCodeBlock></i>
                   </span>
               <table>
               <tr>
               <td align="left">
               <!--#include file = ../Shared/gridHeaderTemplates_Layout.htm-->
               </td>
               <td>
               <telerik:radbutton enablesplitbutton="true" id="SplitButton" autopostback="false"
                   runat="server" text="Transfer Item" onclientclicked="OnClientClicked">
               </telerik:radbutton>           
               <telerik:radcontextmenu id="RadContextMenu1" runat="server" OnClientItemClicked="OnClientItemClicked">
               <Items>
                   <telerik:RadMenuItem id="Temp" >
                   </telerik:RadMenuItem>
               </Items>
           </telerik:radcontextmenu>
               </td>
               </tr>
               </table>                 
               </div>
                
           </CommandItemTemplate>
           <Columns>                                                         
               <telerik:GridClientSelectColumn HeaderStyle-Width="6%" HeaderStyle-HorizontalAlign="Center">
                   <ItemStyle HorizontalAlign="Center" BorderStyle ="None" />
               </telerik:GridClientSelectColumn>                          
           </Columns>               
       </MasterTableView>


Thanks Advance,
Mohamed.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Sep 2012, 07:43 AM
Hi,

Try the following code to populate RadContextMenu.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
      GridCommandItem item = (GridCommandItem)e.Item;
      RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");
      RadContextMenu1.DataSourceID = "SqlDataSource2";
      RadContextMenu1.DataTextField = "name";
      RadContextMenu1.DataFieldParentID = "parent";
      RadContextMenu1.DataFieldID = "id";
    }
}

Thanks,
Shinu.
0
mohamed
Top achievements
Rank 1
answered on 03 Sep 2012, 07:59 AM
Thanks for your reply shinu,
it's not bind anything

int pep = Convert.ToInt16(Globals.Entity.People);
                using (var db = new TBSHelpDeskDataContext(Globals.strCon))
                {
                    var md = (from a in db.Templates where a.EntityID == pep select new { a.EntityID, a.Template_Name }).ToList();
 
                    GridCommandItem item = (GridCommandItem)e.Item;
                    RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");
                    RadContextMenu1.DataSource = md;
                    RadContextMenu1.DataTextField = "Template_Name";
                    //RadContextMenu1.DataFieldParentID = "parent";
                    RadContextMenu1.DataFieldID = "EntityID";
                    RadContextMenu1.DataBind();
                }


Thanks advance,
Mohamed.
0
Shinu
Top achievements
Rank 2
answered on 04 Sep 2012, 05:51 AM
HJi,

Unfortunately I cannot replicate the issue at my end. Here is the full code code that I tried based on your scenario.
aspx:
<telerik:RadGrid  ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="Fals OnItemDataBound="RadGrid1_ItemDataBound">
 <MasterTableView CommandItemDisplay="Top">
   <CommandItemTemplate>          
     <telerik:radcontextmenu id="RadContextMenu1" runat="server"></telerik:radcontextmenu>
   </CommandItemTemplate>
    <Columns>
     . . . .
    </Columns>
 </MasterTableView>
</telerik:RadGrid>
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
      GridCommandItem item = (GridCommandItem)e.Item;
      RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");
      RadContextMenu1.DataSourceID = "SqlDataSource2";
      RadContextMenu1.DataTextField = "name";
      RadContextMenu1.DataFieldParentID = "parent";
      RadContextMenu1.DataFieldID = "id";
    }
}
Also check the following help documentation which explains data binding in Radmenu.
Data Binding Overview

Thanks,
Shinu.
0
New
Top achievements
Rank 1
answered on 04 Sep 2012, 05:54 AM
Thanks For your reply shinu,

    </form>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
        SelectCommand="select * from Templates where EntityID=3"></asp:SqlDataSource>
</body>
</html>

protected void RadGrid_OnItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridCommandItem)
            {
                //GridCommandItem commandItem = (GridCommandItem)e.Item;
                RadComboBox ppl_templates = (RadComboBox)e.Item.FindControl("cmb_templates");
                ppl_templates.DataSource = EntityTemplates.getTemplates(Globals.Entity.People);
                ppl_templates.SelectedValue = EntityTemplates.getDefaultUserTemplate(Globals.Entity.People).ToString();
                ppl_templates.DataBind();
 
 
                //GridCommandItem item = (GridCommandItem)e.Item;
                //RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");               
                //RadContextMenu1.DataSource = DbClient.GetList<Template>("EntityID == " + Convert.ToInt32(Globals.Entity.People));
                //RadContextMenu1.DataTextField = "Template_Name";
                //RadContextMenu1.DataValueField = "TemplateID";               
                //RadContextMenu1.DataBind();
 
                GridCommandItem item = (GridCommandItem)e.Item;
                RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");
                RadContextMenu1.DataSourceID = "SqlDataSource2";
                RadContextMenu1.DataTextField = "Template_Name";
                RadContextMenu1.DataFieldParentID = "EntityID";
                RadContextMenu1.DataFieldID = "TemplateID";

Not bind anything

Thanks Advance ,
Mohamed .
0
mohamed
Top achievements
Rank 1
answered on 04 Sep 2012, 06:18 AM
Thanks For your reply shinu,

</form>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
        SelectCommand="select * from Templates where EntityID=3"></asp:SqlDataSource>
</body>
</html>

protected void RadGrid_OnItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridCommandItem)
            {
                //GridCommandItem commandItem = (GridCommandItem)e.Item;
                RadComboBox ppl_templates = (RadComboBox)e.Item.FindControl("cmb_templates");
                ppl_templates.DataSource = EntityTemplates.getTemplates(Globals.Entity.People);
                ppl_templates.SelectedValue = EntityTemplates.getDefaultUserTemplate(Globals.Entity.People).ToString();
                ppl_templates.DataBind();
  
  
                //GridCommandItem item = (GridCommandItem)e.Item;
                //RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");              
                //RadContextMenu1.DataSource = DbClient.GetList<Template>("EntityID == " + Convert.ToInt32(Globals.Entity.People));
                //RadContextMenu1.DataTextField = "Template_Name";
                //RadContextMenu1.DataValueField = "TemplateID";              
                //RadContextMenu1.DataBind();
  
                GridCommandItem item = (GridCommandItem)e.Item;
                RadContextMenu RadContextMenu1 = (RadContextMenu)item.FindControl("RadContextMenu1");
                RadContextMenu1.DataSourceID = "SqlDataSource2";
                RadContextMenu1.DataTextField = "Template_Name";
                RadContextMenu1.DataFieldParentID = "EntityID";
                RadContextMenu1.DataFieldID = "TemplateID";

Not bind anything in RadContextMenu,
Reply Soon

Thanks Advance ,
Mohamed .

0
mohamed
Top achievements
Rank 1
answered on 05 Sep 2012, 06:01 AM
Please Check that Lnk
http://demos.telerik.com/aspnet-ajax/button/examples/splitbutton/defaultcs.aspx

<telerik:RadButton EnableSplitButton="true" ID="SplitButton" AutoPostBack="false"
                runat="server" Text="Transfer Item" OnClientClicked="OnClientClicked">
            </telerik:RadButton>
            <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientItemClicked="OnClientItemClicked">
                <Items>
                    <telerik:RadMenuItem Text="Transfer Right">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="Transfer Left">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadContextMenu>
I'm Taking This Part and i put in to my form nothing has list out ,
What's the Problem.
I'm using telerik, V.2011.1.519.40

Thanks Advance,
Mohamed
Tags
Menu
Asked by
mohamed
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
mohamed
Top achievements
Rank 1
New
Top achievements
Rank 1
Share this question
or