| 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; |
| } |
| |
| |
| } |