Hi Team,
I want to apply custom filter on a grid which is created using dynamic template column. For that I refer the artical on Custom Option for Filtering but the grid filtering functionality is not working . The ItemCommand code is mentioned here under:
if (e.CommandName == RadGrid.FilterCommandName)
{
e.Canceled = true;
Pair filterPair = (Pair)e.CommandArgument;
string colName = filterPair.Second.ToString();
TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
string newFilter = string.Empty;
newFilter = "[" + filterPair.Second.ToString() + "] like '%" + tbPattern.Text.Trim() + "' OR [" + filterPair.Second.ToString() + "] like '" + tbPattern.Text.Trim() + "%'";
radGrid1.MasterTableView.FilterExpression = newFilter;
radGrid1.Rebind();
}
If I remove the e.Canceled = true; then it works with default filter.
Also i tried with bound column it is working file I think this is issue with template column.
Please let me know what wrong I did ASAP.
Thanks a ton is advance.
Regards,
Manish
The complete code is below.
1 Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridFiltering._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="atk" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<atk:ToolkitScriptManager ID="ScriptManager1" EnablePageMethods="true" EnableScriptLocalization="true"
runat="server" AsyncPostBackTimeout="36000">
</atk:ToolkitScriptManager>
<div>
<telerik:RadGrid ID="radGrid1" runat="server" AutoGenerateColumns="false" EnableLinqExpressions="false"
AllowFilteringByColumn="true" AllowSorting="true" OnItemCommand="radGrid1_ItemCommand">
<mastertableview autogeneratecolumns="false" editmode="InPlace" allowfilteringbycolumn="True"
tablelayout="Auto">
<Columns>
</Columns>
</mastertableview>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
2 Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Configuration;
namespace GridFiltering
{
public partial class _Default : System.Web.UI.Page
{
public bool IsBoundColumn
{
get
{
bool isBoundColumn = false;
if (ConfigurationManager.AppSettings["isBoundColumn"] != null)
Boolean.TryParse(ConfigurationManager.AppSettings["isBoundColumn"].ToString(), out isBoundColumn);
return isBoundColumn;
}
}
protected void Page_Load(object sender, EventArgs e)
{
radGrid1.Columns.Clear();
if (IsBoundColumn)
{
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.HeaderText = "class";
boundColumn.DataField = "class";
boundColumn.AutoPostBackOnFilter = true;
boundColumn.ShowFilterIcon = false;
boundColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
radGrid1.Columns.Add(boundColumn);
boundColumn = new GridBoundColumn();
boundColumn.HeaderText = "SubClass";
boundColumn.DataField = "SubClass";
boundColumn.AutoPostBackOnFilter = true;
boundColumn.ShowFilterIcon = false;
boundColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
radGrid1.Columns.Add(boundColumn);
}
else
{
GridTemplateColumn ItemTmpField = new GridTemplateColumn();
ItemTmpField.ItemTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Item, "class", InfoType.None, "", null, "string", false);
ItemTmpField.HeaderTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Header, "class", InfoType.Command, "", null, "string", false);
ItemTmpField.AutoPostBackOnFilter = true;
ItemTmpField.ShowFilterIcon = false;
ItemTmpField.CurrentFilterFunction = GridKnownFunction.EqualTo;
ItemTmpField.DataField = "class";
radGrid1.Columns.Add(ItemTmpField);
ItemTmpField = new GridTemplateColumn();
ItemTmpField.ItemTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Item, "SubClass", InfoType.None, "", null, "string", false);
ItemTmpField.HeaderTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Header, "SubClass", InfoType.Command, "", null, "string", false);
ItemTmpField.AutoPostBackOnFilter = true;
ItemTmpField.ShowFilterIcon = false;
ItemTmpField.CurrentFilterFunction = GridKnownFunction.EqualTo;
ItemTmpField.DataField = "SubClass";
radGrid1.Columns.Add(ItemTmpField);
}
radGrid1.DataSource = CreateDataSource();
radGrid1.DataBind();
}
private DataTable CreateDataSource()
{
DataTable dt = new DataTable();
DataColumn column = new DataColumn("Class", typeof(String));
Random rd = new Random();
dt.Columns.Add(column);
column = new DataColumn("SubClass", typeof(String));
dt.Columns.Add(column);
column = new DataColumn("StartDate", typeof(DateTime));
dt.Columns.Add(column);
column = new DataColumn("EndDate", typeof(DateTime));
dt.Columns.Add(column);
column = new DataColumn("Number", typeof(Decimal));
dt.Columns.Add(column);
dt.Rows.Add("abcd", "a", DateTime.Today, DateTime.Today.AddDays(2), rd.Next());
dt.Rows.Add("abcd", "b", DateTime.Today.AddDays(1), DateTime.Today.AddDays(3), rd.Next());
dt.Rows.Add("qwer", "a", DateTime.Today.AddMonths(3), DateTime.Today.AddMonths(6), rd.Next());
dt.Rows.Add("qwer", "b", DateTime.Today, DateTime.Today.AddDays(5), rd.Next());
dt.Rows.Add("abcd", "c", DateTime.Today, DateTime.Today.AddDays(1), rd.Next());
return dt;
}
protected void radGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
e.Canceled = true;
Pair filterPair = (Pair)e.CommandArgument;
string colName = filterPair.Second.ToString();
TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
string newFilter = string.Empty;
newFilter = "[" + filterPair.Second.ToString() + "] like '%" + tbPattern.Text.Trim() + "' OR [" + filterPair.Second.ToString() + "] like '" + tbPattern.Text.Trim() + "%'";
radGrid1.MasterTableView.FilterExpression = newFilter;
radGrid1.Rebind();
}
}
}
}
3 Class file(template column etc.)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Data.SqlClient;
using Telerik.Web.UI;
using System.Collections.Generic;
public static class UtilityConstants
{
public const string HipoFirstName = "HIPO FirstName";
public const string HipoLastName = "HIPO LastName";
public const string USERID = "UserId";
}
public enum InfoType
{
Command = 0,
Select = 1,
Include = 2,
Reason = 3,
None = 4,
}
public class DynamicallyTemplatedRadGridHandler : ITemplate
{
#region data memebers
Telerik.Web.UI.GridItemType ItemType;
string FieldName;
InfoType InfoType;
Boolean AllowSorting = false;
string JavascriptAlertMethod = string.Empty;
string[] CollectionInSelectCommand;
string headerCss = "text-left";
public static string chkHeaderClientId = string.Empty;
String ColumnType = String.Empty;
String Format = String.Empty;
bool IsHoverTextRequired = false;
#endregion
#region constructor
public DynamicallyTemplatedRadGridHandler(Telerik.Web.UI.GridItemType item_type, string field_name, InfoType info_type, string _JavascriptMethod, string[] _LinkButtonCollectionInSelectCommand, String columnType)
{
ItemType = item_type;
FieldName = field_name;
InfoType = info_type;
//AllowSorting = Allow_Sorting;
JavascriptAlertMethod = _JavascriptMethod;
CollectionInSelectCommand = _LinkButtonCollectionInSelectCommand;
ColumnType = columnType;
Format = GetDataFormat(field_name);
}
public DynamicallyTemplatedRadGridHandler(Telerik.Web.UI.GridItemType item_type, string field_name, InfoType info_type, string _JavascriptMethod, string[] _LinkButtonCollectionInSelectCommand, String columnType, bool isHoverTextRequired)
{
ItemType = item_type;
FieldName = field_name;
InfoType = info_type;
//AllowSorting = Allow_Sorting;
JavascriptAlertMethod = _JavascriptMethod;
CollectionInSelectCommand = _LinkButtonCollectionInSelectCommand;
ColumnType = columnType;
Format = GetDataFormat(field_name);
IsHoverTextRequired = isHoverTextRequired;
}
#endregion
#region Methods
public void InstantiateIn(Control Container)
{
switch (ItemType)
{
case Telerik.Web.UI.GridItemType.Header:
switch (InfoType)
{
case InfoType.Command:
HtmlGenericControl htmlGenericControl = new HtmlGenericControl("span");
LinkButton header_lnkbtn = new LinkButton();
header_lnkbtn.ToolTip = "Click here to sort";
header_lnkbtn.CommandName = "Sort";
header_lnkbtn.CommandArgument = FieldName;
// htmlGenericControl.Attributes.Add("style", "width: 130px;");
//CommandName and CommandArgument should be above Replace functionality
if (FieldName != null && FieldName.Contains("->"))
{
htmlGenericControl.Attributes.Add("class", headerCss);
((GridTableHeaderCell)Container).Attributes.Remove("style");
((GridTableHeaderCell)Container).Attributes.Add("style", "text-align: left !important;");
string headerName = "<span>";
string proxyCompetency = FieldName;
int length = 0;
while (proxyCompetency.Length > 0)
{
length += 5;
int indexOfArrow = proxyCompetency.IndexOf("->");
if (indexOfArrow > 0)
{
headerName += String.Format("{0}</span><span class='nested-data' title='' style='padding-left: {1}px; margin-left: {1}px;'> ", proxyCompetency.Substring(0, indexOfArrow), length);
proxyCompetency = proxyCompetency.Substring(indexOfArrow + 2);
}
else
{
headerName += String.Format("{0}</span>", proxyCompetency);
break;
}
}
header_lnkbtn.Text = headerName;
}
else
{
if ((IsHoverTextRequired) && (FieldName.Length > 40))
header_lnkbtn.Text = string.Format("<span>{0}</span><a href='javascript:void(0)' class='table-info' title=\"{1}\"></a>", string.Format("{0}...", FieldName.Substring(0, 37)), FieldName.IndexOf('"') > -1 ? FieldName.Replace("\"", "''") : FieldName);
else
header_lnkbtn.Text = FieldName;
}
//header_lnkbtn.Click += new EventHandler(header_lnkbtn_Click);
htmlGenericControl.Controls.Add(header_lnkbtn);
Container.Controls.Add(htmlGenericControl);
break;
case InfoType.Include:
CheckBox field_headchkbox = new CheckBox();
field_headchkbox.ID = "chkHead" + FieldName;
chkHeaderClientId = field_headchkbox.ID;
if (JavascriptAlertMethod != string.Empty)
field_headchkbox.Attributes.Add("onclick", String.Format(JavascriptAlertMethod, chkHeaderClientId));
Container.Controls.Add(field_headchkbox);
field_headchkbox.CssClass = "align-chkbox-center";
break;
case InfoType.Select:
HtmlGenericControl htmlLabel = new HtmlGenericControl("div");
Label lc = new Label();
string strColumnName = FieldName;
if (strColumnName.Length > 15)
{
strColumnName = strColumnName.Substring(0, 12) + "...";
}
lc.Text = "<b>" + strColumnName + "</b>";
htmlLabel.Controls.Add(lc);
Container.Controls.Add(htmlLabel);
HtmlGenericControl htmlCheckbox = new HtmlGenericControl("div");
CheckBox field_chkbox = new CheckBox();
field_chkbox.ID = "cbHeader" + FieldName;
field_chkbox.CssClass = "align-chkbox-center";
if (JavascriptAlertMethod != string.Empty)
field_chkbox.Attributes.Add("onclick", JavascriptAlertMethod);
Container.Controls.Add(field_chkbox);
chkHeaderClientId = field_chkbox.ClientID;
HiddenField field_hdnbox = new HiddenField();
field_hdnbox.ID = "hdn" + FieldName;
//field_hdnbox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_hdnbox);
break;
default:
Literal header_ltrl = new Literal();
header_ltrl.Text = "<b>" + FieldName + "</b>";
Container.Controls.Add(header_ltrl);
break;
}
break;
case Telerik.Web.UI.GridItemType.Item:
case Telerik.Web.UI.GridItemType.AlternatingItem:
switch (InfoType)
{
case InfoType.Command:
((GridTableCell)Container).Attributes.Remove("style");
((GridTableCell)Container).Attributes.Add("nowrap", "nowrap");
LinkButton s = new LinkButton();
ImageButton edit_button = new ImageButton();
edit_button.ID = "edit_button";
edit_button.ImageUrl = "~/images/icon_edit.gif";
edit_button.CommandName = "Edit";
//edit_button.Click += new ImageClickEventHandler(edit_button_Click);
edit_button.ToolTip = "Edit";
Container.Controls.Add(edit_button);
object dataItem = ((GridDataItem)Container.NamingContainer).DataItem;
ImageButton delete_button = new ImageButton();
delete_button.ID = "delete_button";
delete_button.Attributes.Add(UtilityConstants.HipoFirstName, Convert.ToString(DataBinder.GetPropertyValue(dataItem, UtilityConstants.HipoFirstName)));
delete_button.Attributes.Add(UtilityConstants.HipoLastName, Convert.ToString(DataBinder.GetPropertyValue(dataItem, UtilityConstants.HipoLastName)));
delete_button.CommandArgument = Convert.ToString(DataBinder.GetPropertyValue(dataItem, UtilityConstants.USERID));
delete_button.ImageUrl = "~/images/icon_delete_competency.gif";
delete_button.CommandName = "Delete";
delete_button.CssClass = "margin-left-10";
delete_button.ToolTip = "Delete";
if (JavascriptAlertMethod != string.Empty)
delete_button.OnClientClick = JavascriptAlertMethod;//"ShowModal(this,'HIPO Candidate Delete Warning','Are you sure you want to delete this HIPO Candidate?');return false;";
Container.Controls.Add(delete_button);
break;
case InfoType.Select:
HtmlGenericControl htmlDiv = new HtmlGenericControl("div");
foreach (string item in CollectionInSelectCommand)
{
string[] strControl = item.Split(new char[] { '<' });
ImageButton selectLink = new ImageButton();
// LinkButton selectLink = new LinkButton();
selectLink.ID = "img1" + strControl[1].ToString();
// selectLink.ID = "lnk1" + strControl[1].ToString();
//selectLink.CssClass= "text-center";
selectLink.ToolTip = strControl[0].ToString();
selectLink.CommandName = strControl[1].ToString();
htmlDiv.Controls.Add(selectLink);
Container.Controls.Add(htmlDiv);
}
break;
case InfoType.Include:
CheckBox field_chkbox = new CheckBox();
field_chkbox.ID = "chk" + FieldName;
if (JavascriptAlertMethod != string.Empty)
field_chkbox.Attributes.Add("onclick", String.Format(JavascriptAlertMethod, chkHeaderClientId));
Container.Controls.Add(field_chkbox);
field_chkbox.CssClass = "align-chkbox-center";
HiddenField field_hdnbox = new HiddenField();
field_hdnbox.ID = "hdn" + FieldName;
field_hdnbox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_hdnbox);
break;
case InfoType.Reason:
Label field_lblReason = new Label();
field_lblReason.ID = "lbl" + FieldName;
//field_lblReason.ToolTip = FieldName;
field_lblReason.CssClass = "wordwrap";
field_lblReason.Text = String.Empty;
field_lblReason.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lblReason);
RadToolTip radTooltip = new RadToolTip();
radTooltip.ID = "rad" + FieldName;
radTooltip.Animation = ToolTipAnimation.Slide;
radTooltip.RelativeTo = ToolTipRelativeDisplay.Mouse;
radTooltip.ShowEvent = ToolTipShowEvent.OnMouseOver;
radTooltip.ContentScrolling = ToolTipScrolling.Auto;
radTooltip.HideEvent = ToolTipHideEvent.LeaveTargetAndToolTip;
radTooltip.TargetControlID = field_lblReason.ID;
radTooltip.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(radTooltip);
break;
default:
Label field_lbl = new Label();
field_lbl.ID = System.Guid.NewGuid().ToString();
field_lbl.ToolTip = FieldName;
field_lbl.CssClass = "width-120 wordwrap";
field_lbl.Text = String.Empty;
field_lbl.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lbl);
//}
break;
}
break;
case Telerik.Web.UI.GridItemType.EditItem:
if (InfoType == InfoType.Command)
{
LinkButton s = new LinkButton();
ImageButton save_button = new ImageButton();
save_button.ID = "edit_button";
save_button.ImageUrl = "~/images/save-icon.gif";
save_button.CommandName = "Save";
//edit_button.Click += new ImageClickEventHandler(edit_button_Click);
save_button.ToolTip = "Save";
Container.Controls.Add(save_button);
ImageButton cancel_button = new ImageButton();
cancel_button.ID = "delete_button";
cancel_button.ImageUrl = "~/images/struct/cancel-icon.png";
cancel_button.CommandName = "Cancel";
cancel_button.CssClass = "margin-left-10";
cancel_button.ToolTip = "Cancel";
if (JavascriptAlertMethod != string.Empty)
cancel_button.OnClientClick = JavascriptAlertMethod;//"ShowModal(this,'HIPO Candidate Delete Warning','Are you sure you want to delete this HIPO Candidate?');return false;";
Container.Controls.Add(cancel_button);
}
else// for other 'non-command' i.e. the key and non key fields, bind textboxes with corresponding field values
{
TextBox field_txtbox = new TextBox();
field_txtbox.ID = FieldName;
field_txtbox.MaxLength = 512;
field_txtbox.Text = String.Empty;
field_txtbox.CssClass = "width-75";
field_txtbox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_txtbox);
}
break;
case Telerik.Web.UI.GridItemType.Footer:
Label field_lbl_footer = new Label();
field_lbl_footer.ID = FieldName;
field_lbl_footer.Text = String.Empty; //we will bind it later through 'OnDataBinding' event
field_lbl_footer.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lbl_footer);
break;
}
}
/// <summary>
/// Method returns format of data to be shown in grid
/// </summary>
/// <param name="columnName"></param>
/// <returns></returns>
public String GetDataFormat(string columnName)
{
return "";
}
#endregion
#region Event Handlers
private string GetUserId(object obj)
{
return obj.ToString();
}
private void OnDataBinding(object sender, EventArgs e)
{
object bound_value_obj = null;
Control ctrl = (Control)sender;
GridDataItem data_item_container = (GridDataItem)ctrl.NamingContainer;
bound_value_obj = DataBinder.GetPropertyValue(data_item_container.DataItem, FieldName);
switch (ItemType)
{
case Telerik.Web.UI.GridItemType.Item:
if (sender.GetType().ToString() == "System.Web.UI.WebControls.HiddenField")
{
HiddenField hdn_field = sender as HiddenField;
hdn_field.Value = bound_value_obj.ToString();
}
else if (sender.GetType().ToString() == "Telerik.Web.UI.RadToolTip")
{
RadToolTip rad_field = sender as RadToolTip;
if (bound_value_obj.ToString().Trim().Length > 25)
{
rad_field.Text = bound_value_obj.ToString();
}
else
{
rad_field.Visible = false;
}
}
else
{
Label field_ltrl = (Label)sender;
string strName = string.Empty;
strName = bound_value_obj.ToString();
if (FieldName == "Employee Name" || FieldName == "Manager Name" || FieldName == "Nominator Name" || FieldName == "Calibrator Name")
{
if (strName.IndexOf(",") == 0 || strName.IndexOf(",") == strName.Length - 1)
{
strName = strName.Replace(",", "");
}
}
if (FieldName == "Employee Name" && ((System.Data.DataRowView)(data_item_container.DataItem)).DataView.Table.Columns["UserId"] != null)
{
string UID = GetUserId(DataBinder.Eval(data_item_container.DataItem, "UserId"));
string uri = field_ltrl.ResolveClientUrl("~/CandidateProfile/Profile.aspx");
string LINK = "<a title='Click here to view candidate profile' href=" + uri + "?showBack=" + "1" + "&uid=" + UID + ">" + strName + "</a>";
field_ltrl.Text = LINK;
field_ltrl.ToolTip = "";
}
else if (FieldName.ToUpper() == "Title".ToUpper() && ((System.Data.DataRowView)(data_item_container.DataItem)).DataView.Table.Columns["RowNumber"] != null)
{
string RowNumber = GetUserId(DataBinder.Eval(data_item_container.DataItem, "RowNumber"));
string uri = "~/EmployeePortal/RoleProfile.aspx";
uri = field_ltrl.ResolveClientUrl(uri);
string LINK = "<a title='Click here to view Positions/Roles/Committees' href=" + uri + "?showBack=" + "1" + "&RowNumber=" + RowNumber + ">" + strName + "</a>";
field_ltrl.Text = LINK;
field_ltrl.ToolTip = "";
}
else if (FieldName.ToUpper() == "REASON")
{
string str = string.Empty;
str = Convert.ToString(bound_value_obj);
if (str.Length > 25 && ctrl.ID == "lblReason")
{
str = str.Substring(0, 25);
str = str + "...";
field_ltrl.Text = str;
field_ltrl.ToolTip = bound_value_obj.ToString();
}
else
{
if (ColumnType.Trim().Equals("DateTime", StringComparison.InvariantCultureIgnoreCase))
str = Convert.ToDateTime(str).ToString("MM/DD/YYYY");
field_ltrl.Text = String.Format("{0} {1}", str, Format);
}
}
else if (FieldName == "Notes")
{
string UID = GetUserId(DataBinder.Eval(data_item_container.DataItem, "UserId"));
string noteText = DataBinder.Eval(data_item_container.DataItem, "Notes").ToString();
string uri = field_ltrl.ResolveClientUrl("~/CandidateProfile/Note.aspx");
string LINK = "<a title='Click here to view candidate note' href=" + uri + "?uid=" + UID + "&SearchText=" + noteText + ">View</a>";
field_ltrl.Text = LINK;
field_ltrl.ToolTip = "";
}
else if ((FieldName == "Date Started") || (FieldName == "Rotation Date (Low)*") || (FieldName == "Rotation Date (Mid)*") || (FieldName == "Rotation Date (High)*"))
{
if (string.IsNullOrEmpty(strName))
{
strName = "NA";
field_ltrl.Text = strName;
}
else
{
field_ltrl.Text = strName;// String.Format("{0} {1}", strName, Format);
}
field_ltrl.CssClass = "";
GridTableCell td = field_ltrl.Parent as GridTableCell;
td.Attributes.Add("class", "text-left");
td.Attributes.Add("tdalign", "left");
}
else
{
if (ColumnType.Trim().Equals("DateTime", StringComparison.InvariantCultureIgnoreCase) && strName != "" && strName != ConfigurationManager.AppSettings.Get("MultipleValueText"))
strName = Convert.ToString(Convert.ToDateTime(strName).ToString("MM/dd/yyyy"));
if (strName == "")
{
strName = "NA";
field_ltrl.Text = strName;
}
else
field_ltrl.Text = String.Format("{0} {1}", strName, Format);
//double Num;
//bool isNum = double.TryParse(strName, out Num);
//if (isNum)
if ((ColumnType.Trim().Equals("Numeric", StringComparison.InvariantCultureIgnoreCase)) || (ColumnType.Trim().Equals("DateTime", StringComparison.InvariantCultureIgnoreCase)))
{
field_ltrl.CssClass = "";
GridTableCell td = field_ltrl.Parent as GridTableCell;
td.Attributes.Add("class", "text-center wordwrap");
td.Attributes.Add("tdalign", "center");
}
else
{
field_ltrl.CssClass = "";
GridTableCell td = field_ltrl.Parent as GridTableCell;
td.Attributes.Add("class", "width-150 wordwrap");
}
}
}
break;
case Telerik.Web.UI.GridItemType.EditItem:
TextBox field_txtbox = (TextBox)sender;
field_txtbox.Text = bound_value_obj.ToString();
break;
}
}
#endregion
}
I want to apply custom filter on a grid which is created using dynamic template column. For that I refer the artical on Custom Option for Filtering but the grid filtering functionality is not working . The ItemCommand code is mentioned here under:
if (e.CommandName == RadGrid.FilterCommandName)
{
e.Canceled = true;
Pair filterPair = (Pair)e.CommandArgument;
string colName = filterPair.Second.ToString();
TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
string newFilter = string.Empty;
newFilter = "[" + filterPair.Second.ToString() + "] like '%" + tbPattern.Text.Trim() + "' OR [" + filterPair.Second.ToString() + "] like '" + tbPattern.Text.Trim() + "%'";
radGrid1.MasterTableView.FilterExpression = newFilter;
radGrid1.Rebind();
}
If I remove the e.Canceled = true; then it works with default filter.
Also i tried with bound column it is working file I think this is issue with template column.
Please let me know what wrong I did ASAP.
Thanks a ton is advance.
Regards,
Manish
The complete code is below.
1 Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridFiltering._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="atk" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<atk:ToolkitScriptManager ID="ScriptManager1" EnablePageMethods="true" EnableScriptLocalization="true"
runat="server" AsyncPostBackTimeout="36000">
</atk:ToolkitScriptManager>
<div>
<telerik:RadGrid ID="radGrid1" runat="server" AutoGenerateColumns="false" EnableLinqExpressions="false"
AllowFilteringByColumn="true" AllowSorting="true" OnItemCommand="radGrid1_ItemCommand">
<mastertableview autogeneratecolumns="false" editmode="InPlace" allowfilteringbycolumn="True"
tablelayout="Auto">
<Columns>
</Columns>
</mastertableview>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Configuration;
namespace GridFiltering
{
public partial class _Default : System.Web.UI.Page
{
public bool IsBoundColumn
{
get
{
bool isBoundColumn = false;
if (ConfigurationManager.AppSettings["isBoundColumn"] != null)
Boolean.TryParse(ConfigurationManager.AppSettings["isBoundColumn"].ToString(), out isBoundColumn);
return isBoundColumn;
}
}
protected void Page_Load(object sender, EventArgs e)
{
radGrid1.Columns.Clear();
if (IsBoundColumn)
{
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.HeaderText = "class";
boundColumn.DataField = "class";
boundColumn.AutoPostBackOnFilter = true;
boundColumn.ShowFilterIcon = false;
boundColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
radGrid1.Columns.Add(boundColumn);
boundColumn = new GridBoundColumn();
boundColumn.HeaderText = "SubClass";
boundColumn.DataField = "SubClass";
boundColumn.AutoPostBackOnFilter = true;
boundColumn.ShowFilterIcon = false;
boundColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
radGrid1.Columns.Add(boundColumn);
}
else
{
GridTemplateColumn ItemTmpField = new GridTemplateColumn();
ItemTmpField.ItemTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Item, "class", InfoType.None, "", null, "string", false);
ItemTmpField.HeaderTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Header, "class", InfoType.Command, "", null, "string", false);
ItemTmpField.AutoPostBackOnFilter = true;
ItemTmpField.ShowFilterIcon = false;
ItemTmpField.CurrentFilterFunction = GridKnownFunction.EqualTo;
ItemTmpField.DataField = "class";
radGrid1.Columns.Add(ItemTmpField);
ItemTmpField = new GridTemplateColumn();
ItemTmpField.ItemTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Item, "SubClass", InfoType.None, "", null, "string", false);
ItemTmpField.HeaderTemplate = new DynamicallyTemplatedRadGridHandler(GridItemType.Header, "SubClass", InfoType.Command, "", null, "string", false);
ItemTmpField.AutoPostBackOnFilter = true;
ItemTmpField.ShowFilterIcon = false;
ItemTmpField.CurrentFilterFunction = GridKnownFunction.EqualTo;
ItemTmpField.DataField = "SubClass";
radGrid1.Columns.Add(ItemTmpField);
}
radGrid1.DataSource = CreateDataSource();
radGrid1.DataBind();
}
private DataTable CreateDataSource()
{
DataTable dt = new DataTable();
DataColumn column = new DataColumn("Class", typeof(String));
Random rd = new Random();
dt.Columns.Add(column);
column = new DataColumn("SubClass", typeof(String));
dt.Columns.Add(column);
column = new DataColumn("StartDate", typeof(DateTime));
dt.Columns.Add(column);
column = new DataColumn("EndDate", typeof(DateTime));
dt.Columns.Add(column);
column = new DataColumn("Number", typeof(Decimal));
dt.Columns.Add(column);
dt.Rows.Add("abcd", "a", DateTime.Today, DateTime.Today.AddDays(2), rd.Next());
dt.Rows.Add("abcd", "b", DateTime.Today.AddDays(1), DateTime.Today.AddDays(3), rd.Next());
dt.Rows.Add("qwer", "a", DateTime.Today.AddMonths(3), DateTime.Today.AddMonths(6), rd.Next());
dt.Rows.Add("qwer", "b", DateTime.Today, DateTime.Today.AddDays(5), rd.Next());
dt.Rows.Add("abcd", "c", DateTime.Today, DateTime.Today.AddDays(1), rd.Next());
return dt;
}
protected void radGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
e.Canceled = true;
Pair filterPair = (Pair)e.CommandArgument;
string colName = filterPair.Second.ToString();
TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
string newFilter = string.Empty;
newFilter = "[" + filterPair.Second.ToString() + "] like '%" + tbPattern.Text.Trim() + "' OR [" + filterPair.Second.ToString() + "] like '" + tbPattern.Text.Trim() + "%'";
radGrid1.MasterTableView.FilterExpression = newFilter;
radGrid1.Rebind();
}
}
}
}
3 Class file(template column etc.)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Data.SqlClient;
using Telerik.Web.UI;
using System.Collections.Generic;
public static class UtilityConstants
{
public const string HipoFirstName = "HIPO FirstName";
public const string HipoLastName = "HIPO LastName";
public const string USERID = "UserId";
}
public enum InfoType
{
Command = 0,
Select = 1,
Include = 2,
Reason = 3,
None = 4,
}
public class DynamicallyTemplatedRadGridHandler : ITemplate
{
#region data memebers
Telerik.Web.UI.GridItemType ItemType;
string FieldName;
InfoType InfoType;
Boolean AllowSorting = false;
string JavascriptAlertMethod = string.Empty;
string[] CollectionInSelectCommand;
string headerCss = "text-left";
public static string chkHeaderClientId = string.Empty;
String ColumnType = String.Empty;
String Format = String.Empty;
bool IsHoverTextRequired = false;
#endregion
#region constructor
public DynamicallyTemplatedRadGridHandler(Telerik.Web.UI.GridItemType item_type, string field_name, InfoType info_type, string _JavascriptMethod, string[] _LinkButtonCollectionInSelectCommand, String columnType)
{
ItemType = item_type;
FieldName = field_name;
InfoType = info_type;
//AllowSorting = Allow_Sorting;
JavascriptAlertMethod = _JavascriptMethod;
CollectionInSelectCommand = _LinkButtonCollectionInSelectCommand;
ColumnType = columnType;
Format = GetDataFormat(field_name);
}
public DynamicallyTemplatedRadGridHandler(Telerik.Web.UI.GridItemType item_type, string field_name, InfoType info_type, string _JavascriptMethod, string[] _LinkButtonCollectionInSelectCommand, String columnType, bool isHoverTextRequired)
{
ItemType = item_type;
FieldName = field_name;
InfoType = info_type;
//AllowSorting = Allow_Sorting;
JavascriptAlertMethod = _JavascriptMethod;
CollectionInSelectCommand = _LinkButtonCollectionInSelectCommand;
ColumnType = columnType;
Format = GetDataFormat(field_name);
IsHoverTextRequired = isHoverTextRequired;
}
#endregion
#region Methods
public void InstantiateIn(Control Container)
{
switch (ItemType)
{
case Telerik.Web.UI.GridItemType.Header:
switch (InfoType)
{
case InfoType.Command:
HtmlGenericControl htmlGenericControl = new HtmlGenericControl("span");
LinkButton header_lnkbtn = new LinkButton();
header_lnkbtn.ToolTip = "Click here to sort";
header_lnkbtn.CommandName = "Sort";
header_lnkbtn.CommandArgument = FieldName;
// htmlGenericControl.Attributes.Add("style", "width: 130px;");
//CommandName and CommandArgument should be above Replace functionality
if (FieldName != null && FieldName.Contains("->"))
{
htmlGenericControl.Attributes.Add("class", headerCss);
((GridTableHeaderCell)Container).Attributes.Remove("style");
((GridTableHeaderCell)Container).Attributes.Add("style", "text-align: left !important;");
string headerName = "<span>";
string proxyCompetency = FieldName;
int length = 0;
while (proxyCompetency.Length > 0)
{
length += 5;
int indexOfArrow = proxyCompetency.IndexOf("->");
if (indexOfArrow > 0)
{
headerName += String.Format("{0}</span><span class='nested-data' title='' style='padding-left: {1}px; margin-left: {1}px;'> ", proxyCompetency.Substring(0, indexOfArrow), length);
proxyCompetency = proxyCompetency.Substring(indexOfArrow + 2);
}
else
{
headerName += String.Format("{0}</span>", proxyCompetency);
break;
}
}
header_lnkbtn.Text = headerName;
}
else
{
if ((IsHoverTextRequired) && (FieldName.Length > 40))
header_lnkbtn.Text = string.Format("<span>{0}</span><a href='javascript:void(0)' class='table-info' title=\"{1}\"></a>", string.Format("{0}...", FieldName.Substring(0, 37)), FieldName.IndexOf('"') > -1 ? FieldName.Replace("\"", "''") : FieldName);
else
header_lnkbtn.Text = FieldName;
}
//header_lnkbtn.Click += new EventHandler(header_lnkbtn_Click);
htmlGenericControl.Controls.Add(header_lnkbtn);
Container.Controls.Add(htmlGenericControl);
break;
case InfoType.Include:
CheckBox field_headchkbox = new CheckBox();
field_headchkbox.ID = "chkHead" + FieldName;
chkHeaderClientId = field_headchkbox.ID;
if (JavascriptAlertMethod != string.Empty)
field_headchkbox.Attributes.Add("onclick", String.Format(JavascriptAlertMethod, chkHeaderClientId));
Container.Controls.Add(field_headchkbox);
field_headchkbox.CssClass = "align-chkbox-center";
break;
case InfoType.Select:
HtmlGenericControl htmlLabel = new HtmlGenericControl("div");
Label lc = new Label();
string strColumnName = FieldName;
if (strColumnName.Length > 15)
{
strColumnName = strColumnName.Substring(0, 12) + "...";
}
lc.Text = "<b>" + strColumnName + "</b>";
htmlLabel.Controls.Add(lc);
Container.Controls.Add(htmlLabel);
HtmlGenericControl htmlCheckbox = new HtmlGenericControl("div");
CheckBox field_chkbox = new CheckBox();
field_chkbox.ID = "cbHeader" + FieldName;
field_chkbox.CssClass = "align-chkbox-center";
if (JavascriptAlertMethod != string.Empty)
field_chkbox.Attributes.Add("onclick", JavascriptAlertMethod);
Container.Controls.Add(field_chkbox);
chkHeaderClientId = field_chkbox.ClientID;
HiddenField field_hdnbox = new HiddenField();
field_hdnbox.ID = "hdn" + FieldName;
//field_hdnbox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_hdnbox);
break;
default:
Literal header_ltrl = new Literal();
header_ltrl.Text = "<b>" + FieldName + "</b>";
Container.Controls.Add(header_ltrl);
break;
}
break;
case Telerik.Web.UI.GridItemType.Item:
case Telerik.Web.UI.GridItemType.AlternatingItem:
switch (InfoType)
{
case InfoType.Command:
((GridTableCell)Container).Attributes.Remove("style");
((GridTableCell)Container).Attributes.Add("nowrap", "nowrap");
LinkButton s = new LinkButton();
ImageButton edit_button = new ImageButton();
edit_button.ID = "edit_button";
edit_button.ImageUrl = "~/images/icon_edit.gif";
edit_button.CommandName = "Edit";
//edit_button.Click += new ImageClickEventHandler(edit_button_Click);
edit_button.ToolTip = "Edit";
Container.Controls.Add(edit_button);
object dataItem = ((GridDataItem)Container.NamingContainer).DataItem;
ImageButton delete_button = new ImageButton();
delete_button.ID = "delete_button";
delete_button.Attributes.Add(UtilityConstants.HipoFirstName, Convert.ToString(DataBinder.GetPropertyValue(dataItem, UtilityConstants.HipoFirstName)));
delete_button.Attributes.Add(UtilityConstants.HipoLastName, Convert.ToString(DataBinder.GetPropertyValue(dataItem, UtilityConstants.HipoLastName)));
delete_button.CommandArgument = Convert.ToString(DataBinder.GetPropertyValue(dataItem, UtilityConstants.USERID));
delete_button.ImageUrl = "~/images/icon_delete_competency.gif";
delete_button.CommandName = "Delete";
delete_button.CssClass = "margin-left-10";
delete_button.ToolTip = "Delete";
if (JavascriptAlertMethod != string.Empty)
delete_button.OnClientClick = JavascriptAlertMethod;//"ShowModal(this,'HIPO Candidate Delete Warning','Are you sure you want to delete this HIPO Candidate?');return false;";
Container.Controls.Add(delete_button);
break;
case InfoType.Select:
HtmlGenericControl htmlDiv = new HtmlGenericControl("div");
foreach (string item in CollectionInSelectCommand)
{
string[] strControl = item.Split(new char[] { '<' });
ImageButton selectLink = new ImageButton();
// LinkButton selectLink = new LinkButton();
selectLink.ID = "img1" + strControl[1].ToString();
// selectLink.ID = "lnk1" + strControl[1].ToString();
//selectLink.CssClass= "text-center";
selectLink.ToolTip = strControl[0].ToString();
selectLink.CommandName = strControl[1].ToString();
htmlDiv.Controls.Add(selectLink);
Container.Controls.Add(htmlDiv);
}
break;
case InfoType.Include:
CheckBox field_chkbox = new CheckBox();
field_chkbox.ID = "chk" + FieldName;
if (JavascriptAlertMethod != string.Empty)
field_chkbox.Attributes.Add("onclick", String.Format(JavascriptAlertMethod, chkHeaderClientId));
Container.Controls.Add(field_chkbox);
field_chkbox.CssClass = "align-chkbox-center";
HiddenField field_hdnbox = new HiddenField();
field_hdnbox.ID = "hdn" + FieldName;
field_hdnbox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_hdnbox);
break;
case InfoType.Reason:
Label field_lblReason = new Label();
field_lblReason.ID = "lbl" + FieldName;
//field_lblReason.ToolTip = FieldName;
field_lblReason.CssClass = "wordwrap";
field_lblReason.Text = String.Empty;
field_lblReason.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lblReason);
RadToolTip radTooltip = new RadToolTip();
radTooltip.ID = "rad" + FieldName;
radTooltip.Animation = ToolTipAnimation.Slide;
radTooltip.RelativeTo = ToolTipRelativeDisplay.Mouse;
radTooltip.ShowEvent = ToolTipShowEvent.OnMouseOver;
radTooltip.ContentScrolling = ToolTipScrolling.Auto;
radTooltip.HideEvent = ToolTipHideEvent.LeaveTargetAndToolTip;
radTooltip.TargetControlID = field_lblReason.ID;
radTooltip.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(radTooltip);
break;
default:
Label field_lbl = new Label();
field_lbl.ID = System.Guid.NewGuid().ToString();
field_lbl.ToolTip = FieldName;
field_lbl.CssClass = "width-120 wordwrap";
field_lbl.Text = String.Empty;
field_lbl.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lbl);
//}
break;
}
break;
case Telerik.Web.UI.GridItemType.EditItem:
if (InfoType == InfoType.Command)
{
LinkButton s = new LinkButton();
ImageButton save_button = new ImageButton();
save_button.ID = "edit_button";
save_button.ImageUrl = "~/images/save-icon.gif";
save_button.CommandName = "Save";
//edit_button.Click += new ImageClickEventHandler(edit_button_Click);
save_button.ToolTip = "Save";
Container.Controls.Add(save_button);
ImageButton cancel_button = new ImageButton();
cancel_button.ID = "delete_button";
cancel_button.ImageUrl = "~/images/struct/cancel-icon.png";
cancel_button.CommandName = "Cancel";
cancel_button.CssClass = "margin-left-10";
cancel_button.ToolTip = "Cancel";
if (JavascriptAlertMethod != string.Empty)
cancel_button.OnClientClick = JavascriptAlertMethod;//"ShowModal(this,'HIPO Candidate Delete Warning','Are you sure you want to delete this HIPO Candidate?');return false;";
Container.Controls.Add(cancel_button);
}
else// for other 'non-command' i.e. the key and non key fields, bind textboxes with corresponding field values
{
TextBox field_txtbox = new TextBox();
field_txtbox.ID = FieldName;
field_txtbox.MaxLength = 512;
field_txtbox.Text = String.Empty;
field_txtbox.CssClass = "width-75";
field_txtbox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_txtbox);
}
break;
case Telerik.Web.UI.GridItemType.Footer:
Label field_lbl_footer = new Label();
field_lbl_footer.ID = FieldName;
field_lbl_footer.Text = String.Empty; //we will bind it later through 'OnDataBinding' event
field_lbl_footer.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lbl_footer);
break;
}
}
/// <summary>
/// Method returns format of data to be shown in grid
/// </summary>
/// <param name="columnName"></param>
/// <returns></returns>
public String GetDataFormat(string columnName)
{
return "";
}
#endregion
#region Event Handlers
private string GetUserId(object obj)
{
return obj.ToString();
}
private void OnDataBinding(object sender, EventArgs e)
{
object bound_value_obj = null;
Control ctrl = (Control)sender;
GridDataItem data_item_container = (GridDataItem)ctrl.NamingContainer;
bound_value_obj = DataBinder.GetPropertyValue(data_item_container.DataItem, FieldName);
switch (ItemType)
{
case Telerik.Web.UI.GridItemType.Item:
if (sender.GetType().ToString() == "System.Web.UI.WebControls.HiddenField")
{
HiddenField hdn_field = sender as HiddenField;
hdn_field.Value = bound_value_obj.ToString();
}
else if (sender.GetType().ToString() == "Telerik.Web.UI.RadToolTip")
{
RadToolTip rad_field = sender as RadToolTip;
if (bound_value_obj.ToString().Trim().Length > 25)
{
rad_field.Text = bound_value_obj.ToString();
}
else
{
rad_field.Visible = false;
}
}
else
{
Label field_ltrl = (Label)sender;
string strName = string.Empty;
strName = bound_value_obj.ToString();
if (FieldName == "Employee Name" || FieldName == "Manager Name" || FieldName == "Nominator Name" || FieldName == "Calibrator Name")
{
if (strName.IndexOf(",") == 0 || strName.IndexOf(",") == strName.Length - 1)
{
strName = strName.Replace(",", "");
}
}
if (FieldName == "Employee Name" && ((System.Data.DataRowView)(data_item_container.DataItem)).DataView.Table.Columns["UserId"] != null)
{
string UID = GetUserId(DataBinder.Eval(data_item_container.DataItem, "UserId"));
string uri = field_ltrl.ResolveClientUrl("~/CandidateProfile/Profile.aspx");
string LINK = "<a title='Click here to view candidate profile' href=" + uri + "?showBack=" + "1" + "&uid=" + UID + ">" + strName + "</a>";
field_ltrl.Text = LINK;
field_ltrl.ToolTip = "";
}
else if (FieldName.ToUpper() == "Title".ToUpper() && ((System.Data.DataRowView)(data_item_container.DataItem)).DataView.Table.Columns["RowNumber"] != null)
{
string RowNumber = GetUserId(DataBinder.Eval(data_item_container.DataItem, "RowNumber"));
string uri = "~/EmployeePortal/RoleProfile.aspx";
uri = field_ltrl.ResolveClientUrl(uri);
string LINK = "<a title='Click here to view Positions/Roles/Committees' href=" + uri + "?showBack=" + "1" + "&RowNumber=" + RowNumber + ">" + strName + "</a>";
field_ltrl.Text = LINK;
field_ltrl.ToolTip = "";
}
else if (FieldName.ToUpper() == "REASON")
{
string str = string.Empty;
str = Convert.ToString(bound_value_obj);
if (str.Length > 25 && ctrl.ID == "lblReason")
{
str = str.Substring(0, 25);
str = str + "...";
field_ltrl.Text = str;
field_ltrl.ToolTip = bound_value_obj.ToString();
}
else
{
if (ColumnType.Trim().Equals("DateTime", StringComparison.InvariantCultureIgnoreCase))
str = Convert.ToDateTime(str).ToString("MM/DD/YYYY");
field_ltrl.Text = String.Format("{0} {1}", str, Format);
}
}
else if (FieldName == "Notes")
{
string UID = GetUserId(DataBinder.Eval(data_item_container.DataItem, "UserId"));
string noteText = DataBinder.Eval(data_item_container.DataItem, "Notes").ToString();
string uri = field_ltrl.ResolveClientUrl("~/CandidateProfile/Note.aspx");
string LINK = "<a title='Click here to view candidate note' href=" + uri + "?uid=" + UID + "&SearchText=" + noteText + ">View</a>";
field_ltrl.Text = LINK;
field_ltrl.ToolTip = "";
}
else if ((FieldName == "Date Started") || (FieldName == "Rotation Date (Low)*") || (FieldName == "Rotation Date (Mid)*") || (FieldName == "Rotation Date (High)*"))
{
if (string.IsNullOrEmpty(strName))
{
strName = "NA";
field_ltrl.Text = strName;
}
else
{
field_ltrl.Text = strName;// String.Format("{0} {1}", strName, Format);
}
field_ltrl.CssClass = "";
GridTableCell td = field_ltrl.Parent as GridTableCell;
td.Attributes.Add("class", "text-left");
td.Attributes.Add("tdalign", "left");
}
else
{
if (ColumnType.Trim().Equals("DateTime", StringComparison.InvariantCultureIgnoreCase) && strName != "" && strName != ConfigurationManager.AppSettings.Get("MultipleValueText"))
strName = Convert.ToString(Convert.ToDateTime(strName).ToString("MM/dd/yyyy"));
if (strName == "")
{
strName = "NA";
field_ltrl.Text = strName;
}
else
field_ltrl.Text = String.Format("{0} {1}", strName, Format);
//double Num;
//bool isNum = double.TryParse(strName, out Num);
//if (isNum)
if ((ColumnType.Trim().Equals("Numeric", StringComparison.InvariantCultureIgnoreCase)) || (ColumnType.Trim().Equals("DateTime", StringComparison.InvariantCultureIgnoreCase)))
{
field_ltrl.CssClass = "";
GridTableCell td = field_ltrl.Parent as GridTableCell;
td.Attributes.Add("class", "text-center wordwrap");
td.Attributes.Add("tdalign", "center");
}
else
{
field_ltrl.CssClass = "";
GridTableCell td = field_ltrl.Parent as GridTableCell;
td.Attributes.Add("class", "width-150 wordwrap");
}
}
}
break;
case Telerik.Web.UI.GridItemType.EditItem:
TextBox field_txtbox = (TextBox)sender;
field_txtbox.Text = bound_value_obj.ToString();
break;
}
}
#endregion
}