Telerik Forums
UI for ASP.NET AJAX Forum
4 answers
178 views
Hi,

I was wondering if it's possible to do something like this using the TriState checkboxes.

Let's say I have this specific tree, no more than these two levels :
(_) Group 1
   +------- [_] Item 1 
   +------- [_] Item 2
   +------- [_] Item 3
   +------- [_] Item 4
(_) Group 2
   +------- [_] Item 5
   +------- [_] Item 6
   +------- [_] Item 7
   +------- [_] Item 8

Case:
A user could chose one to many items from group 1, or one to many items from group 2. But when they check the group 2 or the items 5 to 8, all the items from group 1 get unckecked.  Or when they check group 1 or any item from 1 to 4, all items from group 2 gets unchecked.

Can this be done easely or I have to catch some client event and program all the JavaScript manually ?

Also, is it possible to have a multi-column items ?

Kind regards,

Michel

Miky
Top achievements
Rank 1
 answered on 28 Feb 2013
2 answers
137 views
Hello,

How can we check if the currently selected view of Radscheduler is Day view using JavaScript? Can anyone provide the JS code to check this condition?

Thanks,
Teena
Princy
Top achievements
Rank 2
 answered on 28 Feb 2013
2 answers
1.1K+ views
I have a old project (from 2010) which is having "Telerik.Web.UI.dll" in the bin folder.  Is there any way to identify if that dll is from licensed version of product or it is a trial version ?

Thanks,
Bhimraj
Bhimraj Ghadge
Top achievements
Rank 1
 answered on 28 Feb 2013
1 answer
49 views
Hello, I was having a strange problem in which RadAutoCompleteBoxes within a FormTemplate within a RadGrid were not rendering properly on first load.  When clicking edit on a particular row and the edit popup came up, the autocomplete control would simply not appear (though I could see it in the rendered HTML).  Oddly, if I cancelled the edit modal and clicked edit again, the autocomplete appeared just fine.

I was able to fix this by adding a DOCTYPE specification on the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Unfortunately, after applying this DOCTYPE setting my RadTextBox controls now resize on hover.  I removed and reapplied the DOCTYPE a few times to make sure that this was the cause of the resizing behavior.  Setting EnableSingleInputRendering="false" reduced the effect, but the height and width seem to increase by about a pixel or so on hover.  Removing the DOCTYPE fixes the resizing problem, but then my autocomplete is broken again.

Any help on this matter would be greatly appreciated.
Galin
Telerik team
 answered on 28 Feb 2013
1 answer
168 views
Hi,

Is it possible to access a Tab in cs page based on the URL to which its pointing? To make the requirement more clear, I have few tabs in my page which got different NavigateUrl values. Based on this value I want to access one particular tab at the server side?

Thanks,
JC.
Princy
Top achievements
Rank 2
 answered on 28 Feb 2013
10 answers
501 views
Hello,

I just had a look at the PivotGrid control - so far it looks quite good. My question is: How can I display data in the Grid that comes from a Sql Server Analysis Services cube?

Thanks for your reply!
Radoslav
Telerik team
 answered on 28 Feb 2013
3 answers
135 views
I need to implement RadGrid with GridAttachmentColumn that is using EntityDataSource. Database schema is like: DocumentID (PK, int), DocumentName(varchar(50)), DocumentDescription(varchar(255)), DocumentData(varbinary(max)). Now, is there an example apart from THIS one, that describes how to use GridAttachmentColumn? I was following this example and unfortunately couldn't get it to work. It seems a bit confusing. Is it possible to use one entity datasource for both file info and file binary data? Means, is it possible to use only one EntityDataSource for CRUD operations with table definition given above?

Thanx
asimptota
Top achievements
Rank 1
 answered on 28 Feb 2013
1 answer
65 views

Hello Sir/Madam,

I m using rad grid with item command and selected index changed events now i want whenever i use item commad current row color should be changed as appear in selected index change event


                                                                                           or


or 2nd possibilty is also here that is i m using three rad grids in which 1st grid id is grd_optnandprcng so that whenever i fired item command of fthis grid then second grid data(id="Req_items") and Third grid data(id="opt_items") should not refresh or ajax refersh image should not appear with it but on selected index changed it should be refresh .

 <telerik:AjaxSetting AjaxControlID="grd_optnandprcng">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Req_items"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="opt_items"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>

so please tell me solution of both possibility.

Thanks
Eyup
Telerik team
 answered on 28 Feb 2013
1 answer
143 views
Hi - I am populating a grid from a datatable, with AutoGenerateColumns=true. I have tried using the master table view Tablelayout=auto property and it still resizes the columns to equal widths despite having some columns with long text and others with id values.  I have client side column resizing turned on - could this be interfering with this working correctly?  Thanks for your help
Eyup
Telerik team
 answered on 28 Feb 2013
1 answer
313 views
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;'>&nbsp;", 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


}

Eyup
Telerik team
 answered on 28 Feb 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?