Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
241 views
Hi,

I have a radgrid which is programmatically created. The user can create its own query and select the columns he would like to display.
I have to object (A et B) with a many to many relationship. A List<A> is the grid datasource and for each row, I have to display all B objects related to the DataItem. That's why I have created a custom column with a dropdownlist control (MyCustomFilteringDDLColumnCS).

The user should also be able to filter the source using a "google like" filter on my custom column. It means that the filter DDL is binded with a list<B>. If the user select a value in the filter DDL , the grid must display all objects A related to the the selected B object.

When the grid is loaded, all columns are well formatted. When the user clicks on the filter DDL, possible values are displayed. The first thing is that if the user selects one of these values, the radgrid is rebind and the content of my custom column disappear. The second thing is that I don't know how to filter the datasource.

One of my problems is related to the ResultRadGrid_ColumnCreating method. I need to pass arguments to the custom column constructor but I don't know how to retrieve them.

I wasn't able to find a complete example of this implementation.

regards

Here is my code : i tried to extract the main methods  but that's not easy because I also have a custom pager ... , I'm still working on it so some lines are there for testing purpose:

aspx page :

private void buildGrid() 
        { 
            this.ResultRadGrid.MasterTableView.Columns.Clear(); 
            if (SelectedRadGrigColList.Items.Count != 0) 
            { 
                this.ResultRadGrid.MasterTableView.Columns.Clear(); 
                Hashtable ddlColumnTable = new Hashtable(); 
                Hashtable lblColumnTable = new Hashtable(); 
                foreach (RadListBoxItem rlbi in SelectedRadGrigColList.Items) 
                { 
                    switch (rlbi.Value) 
                    { 
                        case "Pk_Contribution": 
                            { 
                                DataTable dt = ContributionFactory.GetAllContributionDataTable(); 
                                MyCustomFilteringDDLColumnCS templateColumn = new MyCustomFilteringDDLColumnCS(rlbi.Value, "Pk_Contribution", "Title", dt); 
                                templateColumn.HeaderText = "Contribution Relationship"; 
                                templateColumn.DataField = rlbi.Value; 
                                templateColumn.UniqueName = rlbi.Value; 
                                ResultRadGrid.MasterTableView.Columns.Add(templateColumn); 
                                ddlColumnTable.Add(ResultRadGrid.MasterTableView.Columns.Count - 1, rlbi.Value); 
 
                                break; 
                            } 
                        case "Fk_Enum_ContributionStatus": 
                            { 
                                MyCustomFilteringLabelColumnCS templateColumn = new MyCustomFilteringLabelColumnCS(rlbi.Value, rlbi.Value); 
                                ResultRadGrid.MasterTableView.Columns.Add(templateColumn); 
                                templateColumn.HeaderText = "Contribution Status"; 
                                templateColumn.DataField = rlbi.Value; 
                                templateColumn.UniqueName = rlbi.Value; 
                                lblColumnTable.Add(ResultRadGrid.MasterTableView.Columns.Count - 1, rlbi.Value); 
                                break; 
                            } 
                        default: 
                            { 
                                MyCustomFilteringColumnCS gridColumn = new MyCustomFilteringColumnCS(); 
                                this.ResultRadGrid.MasterTableView.Columns.Add(gridColumn); 
                                gridColumn.DataField = rlbi.Value; 
                                gridColumn.HeaderText = rlbi.Text; 
                                break; 
                            } 
 
                    } 
 
                } 
                Session.Add("DDLGRIDCOLUMNSINDEX", ddlColumnTable); 
                Session.Add("LBLGRIDCOLUMNSINDEX", lblColumnTable); 
            }     
        } 
 
protected void ResultRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
        { 
            List<CustomParam> parameterList = new List<CustomParam>(); 
            List<Contribution> ContribList = new List<Contribution>(); 
 
            ////TODO apply filter 
            DbParameterManager dph = new DbParameterManager(DbParameterManager.ProviderType.SqlClient); 
            CustomParam param1 = new CustomParam(dph.CreateDataParameter("@Pk_Contribution", DbType.Int32)); 
            param1.Value = 11; 
            CustomParam param2 = new CustomParam(dph.CreateDataParameter("@MeetingNotes", DbType.String)); 
            param2.Value = "comment"; 
            parameterList.Add(param1); 
            parameterList.Add(param2); 
 
 
            MyContribClient = new ChannelFactory<IContribution>("IContribution"); 
            IContribution MyServices = MyContribClient.CreateChannel(); 
 
            if (MyContribClient.State == CommunicationState.Opened) 
            { 
                ((IContextChannel)MyServices).OperationTimeout = new TimeSpan(0, 0, 240); 
                ContribList = MyServices.GetContributionUsingSQLQuery("select * from Contribution where Pk_Contribution >= @Pk_Contribution and MeetingNotes = @MeetingNotes", parameterList); 
 
            } 
            else 
            { 
                MyContribClient.Open(); 
                ((IContextChannel)MyServices).OperationTimeout = new TimeSpan(0, 0, 240); 
                ContribList = MyServices.GetContributionUsingSQLQuery("select * from Contribution where Pk_Contribution >= @Pk_Contribution and MeetingNotes = @MeetingNotes", parameterList); 
 
            } 
 
            MyContribClient.Close(); 
 
 
            this.ResultRadGrid.DataSource = ContribList; 
 
        } 
 
protected void ResultRadGrid_ColumnCreating(object sender, GridColumnCreatingEventArgs e) 
        { 
            if ((e.ColumnType == typeof(MyCustomFilteringColumnCS).Name)) 
            { 
                e.Column = new MyCustomFilteringColumnCS(); 
            } 
            if ((e.ColumnType == typeof(MyCustomFilteringDDLColumnCS).Name)) 
            { 
                GridDataItem dataItem = (GridDataItem)((Control)sender).NamingContainer; 
 
                e.Column = new MyCustomFilteringDDLColumnCS(); 
            } 
            if ((e.ColumnType == typeof(MyCustomFilteringLabelColumnCS).Name)) 
            { 
                e.Column = new MyCustomFilteringLabelColumnCS(); 
            } 
 
        } 
 
protected void ResultRadGrid_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if ((e.CommandName == "Filter")) 
            { 
                foreach (GridColumn column in e.Item.OwnerTableView.Columns) 
                { 
                    column.CurrentFilterValue = string.Empty; 
                    column.CurrentFilterFunction = GridKnownFunction.NoFilter; 
                } 
            } 
        } 
 
protected void ResultRadGrid_ItemDataBound(object sender, GridItemEventArgs e) // similar to RowDataBound event in GridView   
        { 
             
            if ((e.Item.ItemType == GridItemType.Item) || (e.Item.ItemType == GridItemType.AlternatingItem))// gets the row collection    
            { 
                RadGrid dg = (RadGrid)sender; 
                int cnt = e.Item.ItemIndex + (dg.PageSize * dg.CurrentPageIndex); 
                List<Contribution> dtBound = (List<Contribution>)dg.DataSource; 
                GridDataItem dataitem = (GridDataItem)e.Item; 
                try 
                { 
                     
                    if (Session["DDLGRIDCOLUMNSINDEX"] != null) 
                    { 
                        Hashtable colIndexTable = (Hashtable)Session["DDLGRIDCOLUMNSINDEX"]; 
                        IEnumerator iter = colIndexTable.Keys.GetEnumerator(); 
                        while (iter.MoveNext()) 
                        { 
                            int i = (int)iter.Current; 
                            string colName = colIndexTable[i].ToString(); 
                            DropDownList ddl = (DropDownList)e.Item.Cells[i].FindControl(colName); 
                            if (ddl != null) 
                            { 
                                int index = 0; 
                                if (dtBound[cnt] != null) 
                                { 
                                    ddl.SelectedValue = dtBound[cnt].Pk_Contribution.ToString(); 
                                } 
                            } 
                        } 
                    } 
                } 
                catch (Exception ee) { } 
            } 
        }   
 


CustomColumns definition Class :

public class MyCustomFilteringDDLColumnCS : GridTemplateColumn 
    { 
 
        #region Item Template for DropDownList 
 
        public class CreateItemTemplateDDL : ITemplate 
        { 
            DataTable dtBind; 
            string strddlName; 
            string strDataValueField; 
            string strDataTextField; 
 
            public MyCustomFilteringDDLColumnCS Column = null; 
 
            public CreateItemTemplateDDL(string DDLName, string DataValueField, string DataTextField, DataTable DDLSource) 
            { 
                this.dtBind = DDLSource; 
                this.strDataValueField = DataValueField; 
                this.strDataTextField = DataTextField; 
                this.strddlName = DDLName; 
            } 
 
            public CreateItemTemplateDDL() 
            { 
 
            } 
            public void InstantiateIn(Control objContainer) 
            { 
                DropDownList ddl = new DropDownList(); 
                ddl.DataBinding += new EventHandler(ddl_DataBinding); 
                objContainer.Controls.Add(ddl); 
            } 
 
            private void ddl_DataBinding(object sender, EventArgs e) 
            { 
                DropDownList ddl = (DropDownList)sender; 
                GridDataItem dataItem = (GridDataItem)((Control)sender).NamingContainer; 
                if(dataItem!=null){ 
                    try { 
                        Contribution ctb = (Contribution)dataItem.DataItem; 
                         
                        if (ctb != null) 
                        { 
                            string test = this.Column.DataField; 
                            //todo use reflection 
                            if (test != null) { 
                                ddl.ID = test; 
                                DataTable dt = ContributionFactory.GetAllContributionDataTable(); 
                                ddl.DataSource = dt; 
                                ddl.DataValueField = test; 
                                ddl.DataTextField = "Title"; 
                            } 
                        } 
                        else { 
                            ddl.ID = strddlName; 
                            ddl.DataSource = dtBind; 
                            ddl.DataValueField = strDataValueField; 
                            ddl.DataTextField = strDataTextField; 
                        } 
 
                    } 
                    catch (Exception ee) { 
                     
                    } 
                } 
 
 
                //ddl.DataBind(); 
            } 
        } 
 
        #endregion Item Template for DropDownList 
         
        public MyCustomFilteringDDLColumnCS() { 
 
            CreateItemTemplateDDL template = new CreateItemTemplateDDL(); 
            template.Column = this; 
            this.ItemTemplate = template; 
        } 
 
        public MyCustomFilteringDDLColumnCS(string DDLName, string DataValueField, string DataTextField, DataTable DDLSource) 
        { 
            CreateItemTemplateDDL template = new CreateItemTemplateDDL(DDLName,DataValueField,DataTextField,DDLSource); 
            template.Column = this; 
            this.ItemTemplate = template; 
        } 
         
        public string DataField 
        { 
            get 
            { 
                object res = this.ViewState["_df"]; 
                if (res != null) 
                { 
                    return (string)res; 
                } 
 
                return String.Empty; 
            } 
            set 
            { 
                this.ViewState["_df"] = value; 
            } 
        } 
 
        protected override string GetFilterDataField() 
        { 
            return this.DataField; 
        } 
 
        //RadGrid will call this method when it initializes the controls inside the filtering item cells 
        protected override void SetupFilterControls(TableCell cell) 
        { 
            base.SetupFilterControls(cell); 
            cell.Controls.RemoveAt(0); 
            RadComboBox combo = new RadComboBox(); 
            combo.ID = ("RadComboBox1" + this.UniqueName); 
            combo.ShowToggleImage = false; 
            combo.Skin = "Office2007"; 
            combo.EnableLoadOnDemand = true; 
            combo.AutoPostBack = true; 
            combo.MarkFirstMatch = true; 
            combo.Height = Unit.Pixel(100); 
            combo.ItemsRequested += this.list_ItemsRequested; 
            combo.SelectedIndexChanged += this.list_SelectedIndexChanged; 
            cell.Controls.AddAt(0, combo); 
            cell.Controls.RemoveAt(1); 
        } 
 
        //RadGrid will cal this method when the value should be set to the filtering input control(s) 
        protected override void SetCurrentFilterValueToControl(TableCell cell) 
        { 
            base.SetCurrentFilterValueToControl(cell); 
            RadComboBox combo = (RadComboBox)cell.Controls[0]; 
            if ((this.CurrentFilterValue != string.Empty)) 
            { 
                combo.Text = this.CurrentFilterValue; 
            } 
        } 
 
        //RadGrid will cal this method when the filtering value should be extracted from the filtering input control(s) 
        protected override string GetCurrentFilterValueFromControl(TableCell cell) 
        { 
            RadComboBox combo = (RadComboBox)cell.Controls[0]; 
            return combo.Text; 
        } 
 
        private void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) 
        { 
            //TODo ; use reflection and custom attributes 
            switch (this.UniqueName) { 
                case "Fk_Enum_ContributionStatus": 
                    { 
                        ((RadComboBox)o).DataSource = GetDataTable(this.UniqueName, e.Text); 
                        ((RadComboBox)o).DataTextField = "Enum_Value"; 
                        ((RadComboBox)o).DataValueField = "Pk_Enum_ContributionStatus"; 
                        break; 
                } 
 
                default: { 
                    ((RadComboBox)o).DataSource = GetContributionTable(this.UniqueName, e.Text); 
                    ((RadComboBox)o).DataTextField = this.UniqueName; 
                    ((RadComboBox)o).DataValueField = this.UniqueName; 
                    break; 
                } 
            } 
             
            ((RadComboBox)o).DataBind(); 
        } 
         
        private void list_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            GridFilteringItem filterItem = (GridFilteringItem)((RadComboBox)o).NamingContainer; 
            if ((this.UniqueName == "Index")) 
            { 
                //this is filtering for integer column type 
                filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName)); 
            } 
            //filtering for string column type 
            filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName)); 
        } 
 
        public static List<Contribution> GetContributionTable(string col, string value) 
        { 
 
            List<Contribution> ContribList = new List<Contribution>(); 
            List<CustomParam> parameterList = new List<CustomParam>(); 
            String tablename = string.Empty; 
            String column = string.Empty; 
 
 
 
            ////TODO apply filter 
            DbParameterManager dph = new DbParameterManager(DbParameterManager.ProviderType.SqlClient); 
            CustomParam param1 = new CustomParam(dph.CreateDataParameter("@" + col, DbType.String)); 
            param1.Value = "%" + value + "%"; 
            parameterList.Add(param1); 
 
 
            ContribList = ContributionFactory.getCustomQueryList("select * from Contribution where " + col + " like @" + col, parameterList); 
 
            return ContribList; 
        } 
 
        public static DataTable GetDataTable(string col, string value) { 
            return Enum_ContributionStatusFactory.GetAllEnum_ContributionStatusDataTable(); 
        } 
 
        public DataTable SelectDistinct(string TableName, DataTable SourceTable, string FieldName) 
        { 
            DataSet ds = new DataSet(); 
            DataTable dt = new DataTable(TableName); 
            dt.Columns.Add(FieldName, SourceTable.Columns[FieldName].DataType); 
 
            object LastValue = null; 
            foreach (DataRow dr in SourceTable.Select("", FieldName)) 
            { 
                if (LastValue == null || !(ColumnEqual(LastValue, dr[FieldName]))) 
                { 
                    LastValue = dr[FieldName]; 
                    dt.Rows.Add(new object[] { LastValue }); 
                } 
            } 
            if (ds != null) 
                ds.Tables.Add(dt); 
            return dt; 
        } 
 
        private bool ColumnEqual(object A, object B) 
        { 
 
            // Compares two values to see if they are equal. Also compares DBNULL.Value. 
            // Note: If your DataTable contains object fields, then you must extend this 
            // function to handle them in a meaningful way if you intend to group on them. 
 
            if (A == DBNull.Value && B == DBNull.Value) //  both are DBNull.Value 
                return true; 
            if (A == DBNull.Value || B == DBNull.Value) //  only one is DBNull.Value 
                return false; 
            return (A.Equals(B));  // value type standard comparison 
        } 
 
        public override bool SupportsFiltering() 
        { 
            return true; 
        } 
 
 
    } 




Pavlina
Telerik team
 answered on 16 Oct 2009
1 answer
171 views
How do I add an item to a listbox which is using Templates using client side javascript?

I want a list box to have two columns.

I was to add an item to the list box using client side javscript.

Can this control do this?

Basically each item is like this

<div><div>left{data bind at runtime using jscript}</div><div>{data bind at runtime using jscript}</div></div>

Where I either databind at runtime or just insert a complete HTML blog into the list item.

Any examples?

Chris
Genady Sergeev
Telerik team
 answered on 16 Oct 2009
1 answer
91 views
I have a rad grid that is using the build in selection box feature (client side). I have a button above the grid. When selecting the button, I would like to be able to run a bit of server side code for each selected item within the grid.

The code requires the IdColumn, which is a column that is not visible, but is returned to the grid.

that is the code should for each selected item, use the Id to execute a stored procedure.

Any help would be much appreciated.
Shinu
Top achievements
Rank 2
 answered on 16 Oct 2009
3 answers
156 views
Hi

i there a possebility to disable the insert,edit & delete options on a child grid in a hierachial grid?
But i need the option on the parent grid.

thanks for the help

cheers from switzerland
Dennis
deam
Top achievements
Rank 1
 answered on 16 Oct 2009
4 answers
211 views
Hi, when I click the "Toggle Full Screen" button, RadEditor expands so that the same "Toggle Full Screen" button at the botton become no more visible.

Can you help me?

Saggiatorius
saggiatorius
Top achievements
Rank 1
 answered on 16 Oct 2009
1 answer
104 views
When I change my skin from Office2007 to Sunset in my c# code-behind, it causes my skin not to render.
Here's the code that caused the error...

    protected void MPL_Proposals_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        if (MPL_Proposals.SelectedItem != null) 
        { 
            var propId = Convert.ToInt64(MPL_Proposals.SelectedValue); 
            var filter = string.Empty; 
            PopulateMpl(propId, filter); 
            RadGrid_MPL.Rebind(); 
 
            RadGrid_MPL.Skin = myProposalId != propId ? "Sunset" : "Office2007"; 
        } 
    } 
 

My grid is "RadGrid_MPL". As long as I don't change its default skin it looks great. But if I try to change it, it removes its style.

Thoughts?
Dimo
Telerik team
 answered on 16 Oct 2009
1 answer
156 views
My company bought the RadControls for asp.net and the first time I have tried to use any of the controls after a uneventful and successful install I get this error:
Error 1 Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Z:\ClosingApp\Default.aspx 14 
What is causing this error?
T. Tsonev
Telerik team
 answered on 16 Oct 2009
1 answer
160 views
We are using Telerik Radcontrols for ASP.NET AJAX in a custom CMS-type application that will be used to host hundreds/thousands of client sites going forward.  The application uses 4 or 5 Telerik controls and for each client we usually start with a standard Telerik control skin and then make some (potentially a LOT of) changes to it for that client.  So far, we have been making a copy of the original skin, giving it a new name and making any changes directly to that copy but I am concerned that as time goes on, Telerik will release changes to the controls that also require changes to the standard skins (like you did in the 2009-Q2 release with radpanelbar) that will require me to go make tweaks to all existing customized client telerik skins in order to deploy a new DLL.  This will get very scary as the number of clients scale up so I am wondering if you would recommend that instead of me making changes directly to a base Telerik skin we should instead use a base skin and then create a separate "custom" CSS file that over-rides any needed changes from the base skin using inheritance?  The thinking is that then if Telerik comes out with new releases that have new versions of skins or modified skins we just plug those in place of the old ones we are using and the custom "over-ride" CSS file for each client continues to do it's thing (in theory).  Is there anything inherently better about the original approach or problems with the proposed new approach that I am not seeing?

Thanks in advance for any help you can offer.
Dimo
Telerik team
 answered on 16 Oct 2009
1 answer
120 views
Hi,

My situation is a few usercontrols all containing a single radtoolbar.
All controls are wrapped in a XmlHttpPanel.
I used this property EnableClientScriptEvaluation="true" so it registers the javascript when reloaded.
That works great.

However when I hover over a different toolbar then the one I have updated,
the hovered image gets placed next to the button.

the source looks like this afterwards.
<A class=rtbWrap  href="#">  
<SPAN class=rtbOut>  
    <SPAN class=rtbMid>  
        <SPAN class=rtbIn>  
            <IMG class=rtbIcon src="../../interface/images/icons/text.gif">  
        <SPAN class=rtbText></SPAN> 
        </SPAN> 
    </SPAN> 
</SPAN> 
<IMG class=rtbIcon src="../../interface/images/icons/text.gif">  
</A> 
instead of this (how it looks on load)
<A class=rtbWrap title="Click to maintain the products scripts" href="#">  
<SPAN class=rtbOut>  
    <SPAN class=rtbMid>  
        <SPAN class=rtbIn>  
            <IMG class=rtbIcon alt="Click to maintain the products scripts" src="../../interface/images/icons/text.gif">  
        <SPAN class=rtbText>Scripts</SPAN> 
        </SPAN> 
    </SPAN> 
</SPAN> 
</A> 
Notice the extra image within the link element.
This only happens after loading a different control with the XmlHttpPanel.

kind regards,
Wim
Peter
Telerik team
 answered on 16 Oct 2009
1 answer
152 views
Hello Guys,

Thanks to another thread I have been able to hide the horizontal scroolbar (using overflow-x:hidden !important; ) , but so far I haven't been able to hide the vertical one, would you please help me

thanks
T. Tsonev
Telerik team
 answered on 16 Oct 2009
Narrow your results
Selected tags
Tags
+? more
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?