Format data in _ItemDataBound event

4 posts, 0 answers
  1. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 15 Oct 2010 Link to this post

    I have the following Multicolumn Combobox on my page:
    <telerik:RadComboBox ID="ddlLineNum" runat="server" DataValueField="all_line_id"
        DataTextField="line_number" Width="250px" Skin="Windows7" HighlightTemplatedItems="True"
        DropDownWidth="290px" AutoPostBack="True">
            <table border="0" cellpadding="0" cellspacing="0">
                    <td style="width: 75px;">
                        <%#DataBinder.Eval(Container.DataItem, "line_number")%>
                    <td style="width: 200px; padding-left: 5px;">
                        <%#DataBinder.Eval(Container.DataItem, "line_description")%>

    The 1st column contains a telephone number.  I would like to format it so it actually looks like one.  I figured I could do it in the _ItemDataBound event, but I can't quite figure it out?
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 18 Oct 2010 Link to this post

    If you're using the ItemTemplate, why not format it using the third parameter offered by the DataBinder.Eval method.

    I hope that helps.
  3. DevCraft R3 2016 release webinar banner
  4. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 18 Oct 2010 Link to this post

    That would work in a perfect world, unfortunately that is not the world this app operates in.  See the content is dynamic.  The content is determined by other choices made on the form.  Sometimes the content is a traditional telephone number, sometimes it's not.  When it's not, I don't want to apply formatting. 

    Thanks anyway.  At least now I know that there even is a 3rd parameter used for formatting. 
  5. Simon
    Simon avatar
    2281 posts

    Posted 25 Oct 2010 Link to this post

    Hi SSirica,

    In this case, you can substitute this:
    <%#DataBinder.Eval(Container.DataItem, "line_number")%>

    with an ASP.NET Literal and set its Text property in the ItemDataBound event handler to the current value. You can find the Literal control in the Item, e.g.
    e.Item.FindControl("Literal1") as Literal;

    You can read more about the ItemDataBound event and its usage here.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top