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

[Solved] ItemDataBound -> Template Column Controls not databound?

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 07 Apr 2009, 09:02 PM
I have a template column:

<

 

telerik:GridTemplateColumn UniqueName="Email1DateTemplate">

 

 

<ItemTemplate>

 

 

    <asp:Button ID="btnEmail1Date" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"invoiceNumber")%>'

 

 

        CommandName="Email1" runat="server" CssClass="button1" Text="Letter 1 Sent" />

 

 

        <asp:Label ID="lblEmail1PostDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"email1Date")%>'></asp:Label>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

OnItemDatabound i check the contents of lblEmail1PostDate and it does not seem to have a value until AFTER databound?? I can find the label control.. but the text property is always blank. One the grid is rendered the text has been put in though?

 

protected

 

void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

 

{

 

if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)

 

{

 

 

 

 

GridDataItem dataItem = (GridDataItem)e.Item;

 

 

Label lblEmail1PostDate = dataItem["Email1DateTemplate"].FindControl("lblEmail1PostDate") as Label;

 

 

if (lblEmail1PostDate != null && lblEmail1PostDate.Text != " ")

 

{

 

Button btnEmail1Date = e.Item.FindControl("btnEmail1Date") as Button;

 

btnEmail1Date.Visible =

false;

 

}

 

else

 

 

 

 

{

lblEmail1PostDate.Text =

"What the?";

 

}

}

}

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Apr 2009, 04:59 AM
Hi Rich,

I tried the following code on my end and it is working fine. Give a try with that and see if it works.

CS:
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            Label lblEmail1PostDate = dataItem["Email1DateTemplate"].FindControl("lblEmail1PostDate"as Label; 
           //........
        } 
    } 


Thanks
Shinu.
Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or