Add Radcombobox as filtering Item in radgrid Progammatically

3 posts, 1 answers
  1. Bali
    Bali avatar
    4 posts
    Member since:
    Dec 2010

    Posted 15 Dec 2010 Link to this post

    Hi Forum,
    Please assist, I am creating the Radgrid programmatically and want to add Radcombox as a filtering item to it. 
     No Clue, and I've tried everything I can find. 
    I want the design output like the attached file.

    Bali.

    here is the code i am using

         rdGrd = new RadGrid();
                rdGrd.AutoGenerateColumns = false;
                rdGrd.AllowPaging = true;           
                rdGrd.AllowSorting = true;
                rdGrd.AllowFilteringByColumn = true;     

                rdGrd.Width = Unit.Pixel(600);
                rdGrd.EnableAJAX = true;
                rdGrd.EnableAJAXLoadingTemplate = true;
                rdGrd.Skin = "None";
                          
                rdGrd.NeedDataSource += new GridNeedDataSourceEventHandler(rdGrd_NeedDataSource);
                rdGrd.ItemDataBound += new GridItemEventHandler(rdGrd_ItemDataBound);
                rdGrd.PageSize = 25;
                rdGrd.ID = "grd";

      GridBoundColumn boundColumn1 = new GridBoundColumn();
                    boundColumn1.DataField = "FirmName";
                    boundColumn1.UniqueName = "Firm";
                    boundColumn1.HeaderText = "Firm";
                    boundColumn1.AllowFiltering = true;                
                    boundColumn1.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    boundColumn1.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    boundColumn1.ItemStyle.VerticalAlign = VerticalAlign.Top;

      //HOW CAN I ADD A RADCOBOBOX HERE AS A FILTERING ITEM

      GridTemplateColumn templateColumnRank = new GridTemplateColumn();
                    templateColumnRank.AllowFiltering = false;
                    templateColumnRank.HeaderTemplate = new NColHeaderTemplate(120, "Rank", "cont3", "2009, 2008", "LeaderRank, LeaderRankM1", "cont4, cont5");
                    templateColumnRank.ItemTemplate = new NColItemTemplate(120, "LeaderRank, LeaderRankM1", "cont1, cont2");

     

      rdGrd.MasterTableView.Columns.Add(templateColumnRank);
                    rdGrd.MasterTableView.Columns.Add(boundColumn1);
      
         this.Controls.Add(rdGrd);

     

    public class NColHeaderTemplate : ITemplate
        {
            protected LiteralControl lControl0;
            private int iColumnWidth;
            private int nColHeader;
            private string sTopLevelColumnName;
            private string sTopLevelColumnNameUniqueID;
            private string[] sNBottomColumnName;
            private string[] sNBottomColSortCommandArgument;
            private string[] sNBottomColumnNameUniqueID;
            private string sCellHorizontalAlign;

            public NColHeaderTemplate(int ColumnWidth, string TopLevelColumnName, string TopLevelColumnNameUniqueID, string NBottomColumnName, string NBottomColSortCommandArgument, string NBottomColumnNameUniqueID)
            {
                iColumnWidth = ColumnWidth;
                sTopLevelColumnName = TopLevelColumnName.Trim();
                sTopLevelColumnNameUniqueID = TopLevelColumnNameUniqueID.Trim();
                sNBottomColumnName = NBottomColumnName.Split(Convert.ToChar(","));
                sNBottomColSortCommandArgument = NBottomColSortCommandArgument.Split(Convert.ToChar(","));
                sNBottomColumnNameUniqueID = NBottomColumnNameUniqueID.Split(Convert.ToChar(","));
                //ColHeaderParam = nColHeaderParam.Split(Convert.ToChar(","));
                nColHeader = sNBottomColumnName.Length;
                sCellHorizontalAlign = "Center";
            }

           
            public void InstantiateIn(System.Web.UI.Control container)
            {
                lControl0 = new LiteralControl();
                lControl0.ID = sTopLevelColumnNameUniqueID;
                lControl0.Text = sTopLevelColumnName;

                Table table = new Table();
                table.Width = Unit.Pixel(iColumnWidth);

                TableRow row1 = new TableRow();
                TableRow row2 = new TableRow();

                TableCell cell11 = new TableCell();
               
                cell11.Controls.Add(lControl0);
                cell11.ColumnSpan = nColHeader;

                row1.Cells.Add(cell11);
                table.Rows.Add(row1);

                for (int i = 0; i < nColHeader; i++)
                {

                    LinkButton lbControl = new LinkButton();
                    lbControl.ID = sNBottomColumnNameUniqueID[i].ToString().Trim();
                    lbControl.Text = sNBottomColumnName[i].ToString().Trim();
                    lbControl.CommandName = "Sort";
                    lbControl.CommandArgument = sNBottomColSortCommandArgument[i].ToString().Trim();

                    TableCell cell = new TableCell();
                    cell.HorizontalAlign = HorizontalAlign.Center
                   
                    cell.Controls.Add(lbControl);
                    cell.Width = iColumnWidth / nColHeader;
                    row2.Cells.Add(cell);

                }

                table.Rows.Add(row2);
                container.Controls.Add(table);
            }
        }

        public class NColItemTemplate : ITemplate
        {

            //protected LiteralControl lControl;
            protected HyperLink lControl;
            private int iColumnWidth;
            private int nColItem;
            private string[] sNBottomDataColumnName;
            private string[] sNBottomDataControlUniqueID;
            private string sBottomDataColumnName;
            private string sCellHorizontalAlign;
           

            public NColItemTemplate(int ColumnWidth, string NBottomDataColumnName, string NBottomDataControlUniqueID)
            {
                sNBottomDataColumnName = NBottomDataColumnName.Split(Convert.ToChar(","));
                sNBottomDataControlUniqueID = NBottomDataControlUniqueID.Split(Convert.ToChar(","));
                nColItem = sNBottomDataColumnName.Length;
                iColumnWidth = ColumnWidth;
                sCellHorizontalAlign = "Center";
            }
           
            public void InstantiateIn(System.Web.UI.Control container)
            {
                Table table = new Table();
                table.Width = Unit.Pixel(iColumnWidth);

                TableRow row1 = new TableRow();
                for (int i = 0; i < nColItem; i++)
                {
                    //lControl = new LiteralControl();
                    lControl = new HyperLink();
                    lControl.ID = sNBottomDataControlUniqueID[i].Trim();
                    lControl.Text = sNBottomDataColumnName[i].ToString().Trim();
                    lControl.DataBinding += new EventHandler(lControl_DataBinding);

                    TableCell cell = new TableCell();
                    cell.HorizontalAlign = HorizontalAlign.Center;
                    cell.VerticalAlign = VerticalAlign.Top;
                   

                    cell.Width = iColumnWidth / nColItem;
                    cell.Controls.Add(lControl);
                    row1.Cells.Add(cell);
                }
                table.Rows.Add(row1);
                container.Controls.Add(table);
                container.Controls.Add(new LiteralControl("<br />"));
            }
            public void lControl_DataBinding(object sender, EventArgs e)
            {
               // LiteralControl l = (LiteralControl)sender;
                HyperLink l = (HyperLink)sender;
                GridDataItem container = (GridDataItem)l.NamingContainer;
                sBottomDataColumnName = l.Text.Trim();
                l.Text = ((DataRowView)container.DataItem)[sBottomDataColumnName].ToString();
                l.Target = "_blank";
                l.NavigateUrl = "http://www.google.com/search?hl=en&q=" + ((DataRowView)container.DataItem)[sBottomDataColumnName].ToString() + "&btnG=Google+Search";

            }

     

        }

  2. Answer
    Yana
    Admin
    Yana avatar
    4795 posts

    Posted 20 Dec 2010 Link to this post

    Hi Bali,

    Please check the other forum thread regarding the same question here.

    Best wishes,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. Bali
    Bali avatar
    4 posts
    Member since:
    Dec 2010

    Posted 23 Dec 2010 Link to this post

    Thanks For your help.

    Bali.
Back to Top