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

ColumnCreating Event

11 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 10 Jun 2009, 01:11 PM
I've tried using this event on a grid with autogenerated columns but to no avail.

I've seen a number of posts here suggesting that a number of people have tried the same thing with little success.

I've also seen a vague reference to this event only firing if the if certain information about the column is unknown.

Could some one:
1. Explain precisely what the conditions need to be for this event to fire;
2. Arrange to have the response to (1) added to the relevant entry in the docs.

TVM.

--
Stuart

11 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 11 Jun 2009, 10:46 AM
No one?

--
Stuart
0
Stuart Hemming
Top achievements
Rank 2
answered on 12 Jun 2009, 10:25 AM
I'm starting to feel unloved...

--
Stuart
0
Accepted
Veli
Telerik team
answered on 15 Jun 2009, 08:36 AM
Hello Stuart,

Indeed, there has been a lot of comments and tryouts to observe the proper behavior of the ColumnCreating event of RadGrid. I will try to explain things as clearly as I can.

RadGrid's ColumnCreating event is fired whenever RadGrid initializes a custom column. By custom column we mean a custom user-created column object inheriting the initial GridBoundColumn, as described in this help article from the online documentation. A thing to note here, is that ColumnCreating will fire only for custom columns created in the code-behind, when we programatically add columns to RadGrid, due to the very early time of firing of this event in the page lifecycle. This is why if we declare our custom column in the aspx page, by the time the page is loaded, the ColumnCreating event should have already been fired. Therefore, it will not fire with programmatic definition of columns.

The ColumnCreating event has been design to support restoration of custom column data when RadGrid's ViewState is loaded. Therefore, it also won't fire on initial page load, but only after a postback, when RadGrid is to restore its properties from the viewstate.

To sum it up, you need to do a couple of things to use the ColumnCreating event:

1. Create a custom column inheriting the GridBoundColumn as described in the above help article.
2. Add the custom column to RadGrid's column collection programmatically in Page_Init ot Page_Load.
3. Expect the event to fire after a postback, when RadGrid is to restore its properties from the viewstate.

I hope it is clearer now. If you share with us what you are trying to achieve, we might be able to better assist you on the approach to take.

Regards,
Veli
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.
0
Stuart Hemming
Top achievements
Rank 2
answered on 15 Jun 2009, 09:15 AM
Veli,

Thanks for that. It was very helpful.

Can I suggest that this information is included in the docs on the page describing this event.

> I hope it is clearer now. If you share with us what you are trying to achieve, we might be
> able to better assist you on the approach to take.
Indeed it is. However, I've managed what I was attempting simply by using the ColumnCreated event instead.

Thanks again.
--
Stuart
0
Veli
Telerik team
answered on 15 Jun 2009, 12:07 PM
Hello Stuart,

I am glad I was able to help. Your request has been taken into consideration, and our updated support documentation will soon reflect the changes, where we have tried to better explain the intended usage of the ColumnCreating event.

All the best,
Veli
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.
0
Varun
Top achievements
Rank 2
answered on 15 May 2012, 10:25 AM
Hi 

Please  help me to implement in the status columns of my grid.
As per the info provided by telerik, I have implemented the below functionality to add dropdownlist filter in one column named "Status"
But its not working. 

ASPX:-


<telerik:RadGrid ID="radGridAuditList" runat="server" AllowFilteringByColumn="true"
            AutoGenerateColumns="false" ShowGroupPanel="true" EnableAjax="true" GridLines="Both"
            AllowPaging="true" PageSize="50" OnNeedDataSource="radGridAuditList_NeedDataSource"
            OnPageIndexChanged="radGridAuditList_PageIndexChanged" OnPageSizeChanged="radGridAuditList_PageSizeChanged"
            OnItemDataBound="radGridAuditList_ItemDataBound" OnItemCommand="radGridAuditList_ItemCommand"
            ItemStyle-Height="100%" ItemStyle-Width="100%" HorizontalAlign="Left" OnColumnCreating="radGridAuditList_ColumnCreating">
            <MasterTableView DataKeyNames="IAAuditID" AlternatingItemStyle-Wrap="false" Height="100%">
                <Columns>
                    <telerik:GridButtonColumn DataTextField='IAAuditName' HeaderText="Audit" SortExpression="IAAuditName"
                        UniqueName="IAAuditName" CommandName="AuditName">
                    </telerik:GridButtonColumn>
                    <telerik:GridDateTimeColumn DataField="IAAuditScheduleStartDate" HeaderText="Start Date"
                        UniqueName="IAAuditScheduleStartDate" PickerType="DatePicker" />
                    <telerik:GridDateTimeColumn DataField="IAAuditScheduleEndDate" HeaderText="End Date"
                        UniqueName="IAAuditScheduleEndDate" PickerType="DatePicker" />
                     
                </Columns>

                <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="IAAuditScheduleStat" SortOrder="Ascending" />
                        </GroupByFields>
                        <SelectFields>
                            <telerik:GridGroupByField FieldName="IAAuditScheduleStat" HeaderText="Status" />
                        </SelectFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
            </MasterTableView>
            <ClientSettings AllowDragToGroup="true" AllowGroupExpandCollapse="True">
                <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                <Resizing AllowColumnResize="true" EnableRealTimeResize="True" />
                <ClientEvents OnGridCreated="GridCreated" />
            </ClientSettings>
            <AlternatingItemStyle Wrap="true" />
            <ItemStyle Wrap="true" />
            <GroupingSettings ShowUnGroupButton="true" />
            <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
        </telerik:RadGrid>



CS File :-

   private void getAuditList(int userId)
        {
            radGridAuditList.DataSource = auditDS;
            radGridAuditList.DataBind();
            MyCustomFilteringColumn col= new MyCustomFilteringColumn();
            col.DataField = "IAAuditScheduleStat";
            col.HeaderText = "Status";
            radGridAuditList.Columns.Add(col);

        }

// Above  MyCustomFilteringColumn  class is same as
 explained in the telerik help : http://www.telerik.com/help/aspnet/grid/grdfilteringwithdropdownlist.html 

//  ColumnCreating is not firing 
 protected void radGridAuditList_ColumnCreating(object sender, GridColumnCreatingEventArgs e)
        {
            if (e.Column.UniqueName == null)
            {
                e.Column = new MyCustomFilteringColumn();
            }
        }

  protected void Page_Load(object sender, EventArgs e)
        {
            userId = Convert.ToInt32(TranslationResourceManagerInfo.tryGetUserId());
            if (!Page.IsPostBack)
            {
     getAuditList(userId);  
}
            .Culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
        }
0
Antonio Stoilkov
Telerik team
answered on 18 May 2012, 07:11 AM
Hi Varun,

You could achieve your scenario by implementing custom filtering with templates following the demos provided below:

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mark
Top achievements
Rank 1
answered on 19 Jun 2012, 05:12 PM
hi Antonio,

In the demo you provided, it's creating customized column in declaration, would customized column be created in autogenerated way?  The reason I need to add customized column because I want to implement the FilteringByColumn to be either DropDownList box for DropDownListCheckBox to contains values available in each column for single or multiple selection.

Do you have example for such scenarios?

Thanks

Mark
0
Antonio Stoilkov
Telerik team
answered on 22 Jun 2012, 09:01 AM
Hi Mark,

You could achieve your scenario but it is not a trivial implementation. You should enable RadGrid custom filtering and enable the RadComboBox CheckBoxes feature. In order to achieve your scenario you could go through the demos and help articles below for more in depth information. Note that the column should be defined or created programatically and auto generated one could not be used.

All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mark
Top achievements
Rank 1
answered on 22 Jun 2012, 12:30 PM
I have found some sample and made much progress about putting custom columns and using RadComboBox to replace TextBox.  The RadComboBox has a selectedIndexChanged event wired up.  The issue is if I turn on the CheckBox feature of RadComboBox, the selecteeddIndexChanged event would get triggered unexpectly, like even I click on the column header to do sorting of another column.

See below example works fine, but in SetupFilterControls when creating RadComboBox, if I do like this would RadGrid act unexpect.

RadComboBox list = new RadComboBox(){CheckBoxes=true};


    public class clsFilteringDropDownCheckBoxColumn : GridBoundColumn
    {
        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);
 
            RadComboBox list = new RadComboBox();
            list.ID = "list" + this.DataField;
 
            list.Height = Unit.Pixel(300);
            list.AutoPostBack = true;
 
            list.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(DropDownCheckBoxColumn_SelectedIndexChanged);
 
            cell.Controls.AddAt(0, list);
            cell.Controls.RemoveAt(1);
 
            list.DataTextField = this.DataField;
            list.DataValueField = this.DataField;
 
            list.DataSource = this.ListDataSource;
            list.DataBind();
 
        }
        void DropDownCheckBoxColumn_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridFilteringItem filterItem = (sender as RadComboBox).NamingContainer as GridFilteringItem;
 
            this.SelectedValue = (sender as RadComboBox).SelectedValue;
            this.FilteredColumnName = this.UniqueName;
 
            if (this.UniqueName == "Index")
            {
                //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);
 
            RadComboBox list = (RadComboBox)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)
        {
            RadComboBox list = (RadComboBox)cell.Controls[0];
 
            return list.SelectedValue;
        }
        public override GridColumn Clone()
        {
            return base.Clone();
        }
        protected override string GetFilterDataField()
        {
            return this.DataField;
        }
 
    }
}


0
Antonio Stoilkov
Telerik team
answered on 22 Jun 2012, 02:12 PM
Hello Mark,

I have assembled a sample project trying to replicate the issue but without success. You could take a look at the provided project and see if I may be leaving something out.

In order to further investigate you could open a formal ticket uploading a modified version of the provided project which shows the unwanted behavior or creating a sample project demonstrating the issue.

Kind regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Veli
Telerik team
Varun
Top achievements
Rank 2
Antonio Stoilkov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or