This is a migrated thread and some comments may be shown as answers.

[Solved] error on setting a custom column

1 Answer 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jols
Top achievements
Rank 2
Jols asked on 08 May 2009, 03:47 PM
hello to all expert
 
                 Good Day ! i try to follow the again the document on setting a radcombobox inside the grid and also in the source by making a custom template for combobox..

here my source codes in intire grid

<%@ Page Language="C#" MasterPageFile="~/IBOSMaster.Master" AutoEventWireup="true" CodeBehind="CARDTL.aspx.cs" Inherits="IBOS.CAR.CARDTL" Title="CAR DTL" %> 
<%@ MasterType VirtualPath="~/IBOSMaster.master" %> 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
<%@ Register Namespace="RadGrid" TagPrefix="custom" %>    
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
 
     <table style="width: 846px">  
        <tr> 
        </tr> 
        <tr> 
            <td style="width: 805px">  
                <table width="100%">  
                    <tr> 
                        <td style="width: 49px">  
                            <asp:Label ID="Label2" runat="server" CssClass="captionField" Text="DATE :" Width="52px"></asp:Label></td>  
                        <td style="width: 154px">  
                            <telerik:RadDatePicker ID="rdDate" runat="server" MinDate="1900/1/1" Width="150px" Skin="Default2006" AutoPostBack="True" OnSelectedDateChanged="rdDate_SelectedDateChanged">  
                                <DateInput runat="server"   LabelCssClass="radLabelCss_Default2006" Skin="Default2006" AutoPostBack="True">  
                                </DateInput> 
                                <Calendar runat="server"   Skin="Default2006" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" 
                                    ViewSelectorText="x">  
                                </Calendar> 
                                <DatePopupButton CssClass="radPopupImage_Default2006" /> 
                            </telerik:RadDatePicker> 
                            &nbsp;  
                              
                           </td> 
                        <td style="width: 41px">  
                                        <asp:LinkButton ID="LinkButton1" runat="server" CssClass="captionField" Width="57px">SEARCH :</asp:LinkButton></td>  
                        <td style="width: 34px">  
                                        <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Search-002.png" /> 
                        </td> 
                        <td style="width: 23px">  
                                        <asp:LinkButton ID="lnkViewSetting" runat="server" CssClass="captionField" OnClick="lnkViewSetting_Click1" Width="98px">VIEW SETTINGS :</asp:LinkButton></td>  
                        <td style="width: 33px">  
                                        <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Control2-002.png" /> 
                        </td> 
                        <td style="width: 37px">  
                                        <asp:Label ID="Label1" runat="server" 
                                            Text="LINE :" CssClass="captionField" Width="33px"></asp:Label></td>  
                        <td style="width: 41px">  
                            <telerik:RadComboBox ID="rcbLine" runat="server" AutoPostBack="False" CssClass="textContent" 
                                            Skin="Office2007" Width="87px" OnSelectedIndexChanged="rcbLine_SelectedIndexChanged">  
                                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                        </telerik:RadComboBox> 
                        </td> 
                        <td style="width: 2px">  
                        </td> 
                        <td> 
                        </td> 
                    </tr> 
                </table> 
            </td> 
        </tr> 
        <tr style="font-size: 12pt" align = "left">  
            <td style="width: 805px">  
                <asp:Panel ID="pnlGrid" runat="server" Height="520px" ScrollBars="Auto" Width="837px">  
                  
                      
                     
 
                      
                    <telerik:RadGrid runat="server"  AutoGenerateColumns="False" ID="dgDTL" OnNeedDataSource = "dgDTL_NeedDataSource" 
                    Skin="WebBlue" AllowFilteringByColumn="True" AllowSorting="True" PageSize="15"   
                    ShowStatusBar="True" ShowFooter="True" AllowMultiRowSelection = "True" AllowPaging ="True" 
                    GridLines="None" OnItemDataBound="dgDTL_ItemDataBound" Font-Names = "Tahoma" OnItemCreated="dgDTL_ItemCreated" OnColumnCreating="dgDTL_ColumnCreating" OnItemCommand="dgDTL_ItemCommand" En> 
                        <PagerStyle Mode="NextPrevAndNumeric" /> 
                        <MasterTableView DataKeyNames ="fxISTResponseKey">  
                            <HeaderStyle Width="150px" /> 
                            <RowIndicatorColumn Visible="True">  
                                <HeaderStyle Width="20px" /> 
                            </RowIndicatorColumn> 
                            <ExpandCollapseColumn> 
                                <HeaderStyle Width="20px" /> 
                            </ExpandCollapseColumn> 
                              
                            <Columns>    
                              
                            <telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn">  
                            </telerik:GridClientSelectColumn>                        
                            <telerik:GridBoundColumn Visible = "False" DataField="fxMemberKeyISS" HeaderText="ISSUER" SortExpression="fxMemberKeyISS" UniqueName="fxMemberKeyISS" Aggregate="Count">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn  DataField="IssBank" HeaderText="ISSUER" SortExpression="IssBank" UniqueName="IssBank">  
                                
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn Visible = "False" DataField="fxMemberKeyACR" HeaderText="ACQUIRER" SortExpression="fxMemberKeyACR" UniqueName="fxMemberKeyACR" Aggregate="Count">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="AcqBank" HeaderText="ACQUIRER" SortExpression="AcqBank" UniqueName="AcqBank">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="TRF" HeaderText="TRF" SortExpression="TRF" UniqueName="TRF">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fnTerminalNumber" HeaderText="TERM NO" SortExpression="fnTerminalNumber" 
                                UniqueName="fnTerminalNumber">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fnTraceNumber" HeaderText="TRACE NO. ISSUER/ACQUIRER/TRF" SortExpression="fnTraceNumber" 
                                UniqueName="fnTraceNumber">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fnCardNumber" HeaderText="CARD NO." SortExpression="fnCardNumber" 
                                UniqueName="fnCardNumber">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fcPCode" HeaderText="TRANS TYPE" SortExpression="fcPCode" 
                                UniqueName="fcPCode" Visible = "False">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fcTransTypeName" HeaderText="TRANS TYPE" SortExpression="fcTransTypeName" 
                                UniqueName="fcTransTypeName">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridDateTimeColumn DataField="fdTransDate" HeaderText="DATE" SortExpression="fdTransDate"    
                                DataFormatString="{0:d}" UniqueName="fdTransDate" > 
                            </telerik:GridDateTimeColumn > 
                  
                      
                            <telerik:GridBoundColumn DataField="fdTransTime" HeaderText="TIME" SortExpression="fdTransTime" 
                                DataFormatString="{0:T}" UniqueName="fdTransTime">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fxISTResponseKey_Res" HeaderText="TRAN CLASSF" SortExpression="fxISTResponseKey_Res" 
                                UniqueName="fxISTResponseKey_Res" Visible="False">  
                            </telerik:GridBoundColumn> 
                              
//i'm having error here object not set to instance of an object                           
<custom:MyCustomFilteringColumn DataField="fcISTResponseMsg" HeaderText="TRAN CLASSF" UniqueName="fcISTResponseMsg"/>  
                              
                              
                              
                            <telerik:GridBoundColumn DataField="fcISTResponseMsg" HeaderText="TRAN CLASSF" SortExpression="fcISTResponseMsg" 
                                UniqueName="fcISTResponseMsg">  
                            </telerik:GridBoundColumn> 
                                 
                          
 
                            <telerik:GridBoundColumn DataField="fnAccountNumFrom" HeaderText="ACCOUNT FROM" SortExpression="fnAccountNumFrom" 
                                UniqueName="fnAccountNumFrom">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="fnAccountNumTo" HeaderText="ACCOUNT TO" SortExpression="fnAccountNumTo" 
                                UniqueName="fnAccountNumTo">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridNumericColumn  DataField="fnTransAmount" DataType="System.Decimal" HeaderText="AMOUNT" SortExpression="fnTransAmount" 
                                UniqueName="fnTransAmount" Aggregate ="Sum" NumericType="Number">  
                                <FooterStyle Font-Bold="True" /> 
                            </telerik:GridNumericColumn> 
                            <telerik:GridNumericColumn  DataField="fnTransFee" DataType="System.Decimal" HeaderText="FEES" SortExpression="fnTransFee" 
                                UniqueName="fnTransFee" NumericType="Number">  
                                <FooterStyle Font-Bold="True" /> 
                            </telerik:GridNumericColumn> 
                            <telerik:GridNumericColumn  DataField="fnAmountReverse" DataType="System.Decimal" HeaderText="AMOUNT REVERSE" SortExpression="fnAmountReverse" 
                                UniqueName="fnAmountReverse" Aggregate ="Sum" NumericType="Number">  
                                <FooterStyle Font-Bold="True" /> 
                            </telerik:GridNumericColumn> 
                            <telerik:GridNumericColumn  DataField="fnAmountDispense" DataType="System.Decimal" HeaderText="AMOUNT DISPENSE" 
                                SortExpression="fnAmountDispense" UniqueName="fnAmountDispense" Aggregate ="Sum" NumericType="Number">  
                                <FooterStyle Font-Bold="True" /> 
                            </telerik:GridNumericColumn> 
                            <telerik:GridNumericColumn  DataField="fnAmountRecon" DataType="System.Decimal" HeaderText="RECON AMOUNT" SortExpression="fnAmountRecon" 
                                UniqueName="fnAmountRecon" Aggregate ="Sum" NumericType="Number">  
                                <FooterStyle Font-Bold="True" /> 
                            </telerik:GridNumericColumn> 
                 
                            <telerik:GridBoundColumn DataField="fxTransStatusKey" HeaderText="STATUS" SortExpression="fxTransStatusKey" 
                                UniqueName="fxTransStatusKey">  
                            </telerik:GridBoundColumn> 
                              
                            <telerik:GridBoundColumn DataField="fxDTLRemarksKey" HeaderText="REMARKS" SortExpression="fxDTLRemarksKey" 
                                UniqueName="fxDTLRemarksKey">  
                            </telerik:GridBoundColumn> 
                              
                            <telerik:GridBoundColumn DataField="fxChannelKey" HeaderText="CHANNEL" SortExpression="fxChannelKey" 
                                UniqueName="fxChannelKey">  
                            </telerik:GridBoundColumn> 
                              
                            <telerik:GridBoundColumn DataField="fcMsgNumber" HeaderText="fcMsgNumber" SortExpression="fcMsgNumber" 
                                UniqueName="fcMsgNumber" Visible ="False">  
                            </telerik:GridBoundColumn> 
                              
                            <telerik:GridBoundColumn DataField="fxISTResponseKey_Rev" HeaderText="fxISTResponseKey_Rev" SortExpression="fxISTResponseKey_Rev" 
                                UniqueName="fxISTResponseKey_Rev" Visible ="False">  
                            </telerik:GridBoundColumn> 
                                    
                                   
                                      
 
                        </Columns> 
                          
                        </MasterTableView> 
                        <ClientSettings AllowColumnsReorder="True" AllowKeyboardNavigation="True" ReorderColumnsOnClient="True">  
                            <Selecting AllowRowSelect="True" /> 
                            <Resizing AllowColumnResize="True" AllowRowResize="True" /> 
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" FrozenColumnsCount="1">  
                            </Scrolling> 
                        </ClientSettings> 
                        <FilterMenu EnableTheming="True" Skin="Vista">  
                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                        </FilterMenu> 
                    </telerik:RadGrid></asp:Panel> 
            </td> 
        </tr> 
        <tr style="font-size: 12pt">  
            <td style="width: 805px">  
                <div align = "right">  
                    &nbsp;  
                    <asp:Button ID="btnUndo" runat="server" CssClass="captionField" Text="UNDO" OnClick="btnUndo_Click" Width="135px" /> 
                    <asp:Button ID="btnCommitChanges" runat="server" CssClass="captionField" Text="COMMIT CHANGES" OnClick="btnCommitChanges_Click" /></div></td> 
        </tr> 
        <tr style="font-size: 12pt">  
            <td style="width: 805px">  
                <table width="100%">  
                    <tr> 
                        <td> 
                            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                                <AjaxSettings> 
                                   <telerik:AjaxSetting AjaxControlID="dgDTL">  
                                            <UpdatedControls> 
                                                <telerik:AjaxUpdatedControl ControlID="dgDTL" /> 
                                            </UpdatedControls> 
                                        </telerik:AjaxSetting> 
                                        <telerik:AjaxSetting AjaxControlID="clrFilters">  
                                            <UpdatedControls> 
                                                <telerik:AjaxUpdatedControl ControlID="dgDTL" /> 
                                                <telerik:AjaxUpdatedControl ControlID="clrFilters" /> 
                                            </UpdatedControls> 
                                        </telerik:AjaxSetting> 
                                </AjaxSettings>   
                            </telerik:RadAjaxManager> 
                            <telerik:RadMenu ID="mnuDTL" runat="server" OnItemClick="mnuDTL_ItemClick" Skin="WebBlue">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                            </telerik:RadMenu> 
                            &nbsp;</td> 
                    </tr> 
                </table> 
 
            </td> 
        </tr> 
    </table> 
 
 
</asp:Content> 
 
and here's my class

using System.Data.SqlClient;    
using System.Data;  
using Telerik.Web.UI ;  
using System.Web.UI.WebControls;  
using System.Web.UI;  
using System;  
using System.Collections;  
 
namespace RadGrid  
{  
    public class MyCustomFilteringColumn: GridBoundColumn   
    {  
        //Properties for boolean/checkbox dropdown    
        //public string TrueText { get;set;}  
        //public string FalseText { get; set; }  
 
        private object listDataSource = null;  
 
        //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);  
 
            System.Web.UI.WebControls.DropDownList list = new System.Web.UI.WebControls.DropDownList();  
            list.ID = "list" + this.DataField;  
 
            list.Height = Unit.Pixel(300);  
            list.AutoPostBack = true;  
 
            list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);  
 
            cell.Controls.AddAt(0, list);  
            cell.Controls.RemoveAt(1);  
 
            //If boolean, assume CHECKBOX    
            if (this.DataType.ToString() == "System.Boolean")  
            {  
                DataTable dtBool = new DataTable();  
                dtBool.Columns.Add(this.DataField, Type.GetType("System.Boolean"));  
                dtBool.Columns.Add("description", Type.GetType("System.String"));  
 
                //Blank row    
                DataRow drBlank = dtBool.NewRow();  
                drBlank["description"] = "";  
                dtBool.Rows.Add(drBlank);  
 
                ////Checked row    
                //DataRow drTrue = dtBool.NewRow();  
                //drTrue["description"] = TrueText;  
                //drTrue[this.DataField] = 1;  
                //dtBool.Rows.Add(drTrue);  
 
                ////Unchecked row    
                //DataRow drFalse = dtBool.NewRow();  
                //drFalse["description"] = FalseText;  
                //drFalse[this.DataField] = 0;  
                //dtBool.Rows.Add(drFalse);  
 
                list.DataSource = dtBool;  
                list.DataTextField = "description";  
                list.DataValueField = this.DataField;  
                list.DataBind();  
 
            }  
            else  
            {  
                list.DataTextField = this.DataField;  
                list.DataValueField = this.DataField;  
 
                list.DataSource = this.ListDataSource;  
                list.DataBind();  
            }  
 
        }  
 
        void list_SelectedIndexChanged(object sender, EventArgs e)  
        {  
            GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;  
 
            this.SelectedValue = (sender as DropDownList).SelectedValue;  
            thisthis.FilteredColumnName = this.UniqueName;  
 
            if (this.UniqueName == "Index" || this.DataType.ToString() == "System.Boolean")  
            {  
                //this is example for 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 object ListDataSource  
        {  
            get  
            {  
                return this.listDataSource;  
            }  
            set  
            {  
                listDataSource = value;  
            }  
        }  
        public string SelectedValue  
        {  
            get  
            {  
                object res = this.Owner.OwnerGrid.Page.Session["SelectedValue"];  
                if (res != null)  
                {  
                    return (string)res;  
                }  
                return "";  
            }  
            set  
            {  
                this.Owner.OwnerGrid.Page.Session["SelectedValue"] = value;  
            }  
        }  
        public string FilteredColumnName  
        {  
            get  
            {  
                object res = this.Owner.OwnerGrid.Page.Session["FilteredColumnName"];  
                if (res != null)  
                {  
                    return (string)res;  
                }  
                return "";  
            }  
            set  
            {  
                this.Owner.OwnerGrid.Page.Session["FilteredColumnName"] = value;  
            }  
        }  
        //RadGrid will call this method when the value should be set to the filtering input control(s)    
        protected override void SetCurrentFilterValueToControl(TableCell cell)  
        {  
            base.SetCurrentFilterValueToControl(cell);  
 
            System.Web.UI.WebControls.DropDownList list = (System.Web.UI.WebControls.DropDownList)cell.Controls[0];  
            if (this.CurrentFilterValue != string.Empty)  
            {  
                list.SelectedValue = this.CurrentFilterValue;  
            }  
        }  
 
        //RadGrid will call this method when the filtering value should be extracted from the filtering input control(s)    
        protected override string GetCurrentFilterValueFromControl(TableCell cell)  
        {  
            System.Web.UI.WebControls.DropDownList list = (System.Web.UI.WebControls.DropDownList)cell.Controls[0];  
 
            return list.SelectedValue;  
        }  
        public override GridColumn Clone()  
        {  
            return base.Clone();  
        }  
        protected override string GetFilterDataField()  
        {  
            return this.DataField;  
        }  
 
    }    
 
   }  
   
 
 
please help i cant configure what happen..

sample codes is highly appreciated

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 11 May 2009, 04:44 PM

Hello Jols,

You can use the source code from this online demo:

http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product=grid

which is available in the RadControls installation at the following location:

C:\Program Files\telerik\RadControls for ASPNET AJAX Q1 2009\Live Demos\Controls\Examples\Integration\GridAndCombo

C:\Program Files\telerik\RadControls for ASPNET AJAX Q1 2009\Live Demos\App_Code\Grid\MyCustomFilteringColumnCS.cs


and modify them accordingly in par with your preferences. Let us know if you encounter any particular issues during the process.

Regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jols
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
Share this question
or