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

ColumnCreating vs ColumnCreated vs HUH??

2 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin Schneider
Top achievements
Rank 1
Kevin Schneider asked on 10 Dec 2008, 07:53 PM

I'm banging my head off the wall here trying to understand why these events aren't being called like I would expect them to.

If you look at my grid definition below you'll see its very basic.

My question is why does ColumnCreated get called over 30 times even though I have 2 columns?  When debugging I can see they're "GridExpandColumn's".  But here's the kicker:  It's never called for EITHER of my 2 columns I've defined below.

I also tried hooking up OnColumnCreating and it doesn't even get called at all.  So you have Created getting called over 30 times, and Creating getting called 0 times.  This doesn't make sense to me.  Normally the Creating event preludes the Created event.

What I am actually trying to do is localize the HeaderText value on the columns.  Not from a .NET resource file but from a database driven implementation. Now normally I would just insert some script blocks and change the HeaderText property to something like HeaderText='<%# ResourceHelper.GetString("keyName") %>' but its not a databound control and doesn't let me.

So I wanted to use ColumnCreated to just feed in whatever I set in the HeaderText value into my ResourceHelper class and return a string.

What do you suggest?

<Telerik:RadGrid ID="grdLanguage" runat="server" SkinID="Default" AllowPaging="True" AllowSorting="True" Width="500px" OnColumnCreated="grdLanguage_ColumnCreated" OnItemCommand="grdLanguage_ItemCommand" OnNeedDataSource="grdLanguage_NeedDataSource">  
    <PagerStyle AlwaysVisible="True" Position="Bottom" /> 
    <ClientSettings EnableRowHoverStyle="True" Selecting-AllowRowSelect="True" Resizing-AllowColumnResize="True" /> 
    <MasterTableView DataKeyNames="LanguageId" EditMode="InPlace" AllowFilteringByColumn="False" AutoGenerateColumns="False" CommandItemDisplay="Top" AllowSorting="True" AllowNaturalSort="False" EnableHeaderContextMenu="True">  
        <ItemStyle Height="22px" /> 
        <AlternatingItemStyle Height="22px" /> 
        <CommandItemTemplate> 
            [Insert controls here...removed for simplicity]  
        </CommandItemTemplate> 
        <PagerTemplate> 
            <UserControl:RadGridPager ID="pgLanguage" runat="server" /> 
        </PagerTemplate> 
        <SortExpressions> 
            <Telerik:GridSortExpression FieldName="LanguageName" /> 
        </SortExpressions> 
        <Columns> 
            <Telerik:GridBoundColumn Groupable="False" DataField="LanguageName" SortExpression="LanguageName" UniqueName="LanguageName" HeaderText="Language" /> 
            <Telerik:GridBoundColumn Groupable="False" DataField="CultureName" SortExpression="CultureName" UniqueName="CultureId" HeaderText="Culture" ItemStyle-Width="150px" /> 
        </Columns> 
    </MasterTableView> 
</Telerik:RadGrid> 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2008, 06:51 AM
Hello Kevin,

ColumnCreated event is used for AutoGenerated Columns whereas if you want to make changes to manually created columns, you can use Prerender event of the grid. Check out the code below to understand how to access the header in the PreRender event.
cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    {         
          foreach (GridColumn col in RadGrid1.Columns) 
               { 
                   if (col.UniqueName == "columnUniqueName") 
                        col.HeaderText == "Text"; 
               } 
    } 
 

Thanks
Princy.
0
Kevin Schneider
Top achievements
Rank 1
answered on 11 Dec 2008, 01:57 PM
I have already tried this...

Even something as simple as what is below doesn't work.  The event fires too late.  If a postback occurs then the text will update but not on page load.

protected void grdLanguage_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridColumn column in grdLanguage.Columns) 
        { 
            column.HeaderText = "ABCDEFG"
        } 
    } 



Tags
Grid
Asked by
Kevin Schneider
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kevin Schneider
Top achievements
Rank 1
Share this question
or