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

Format data in _ItemDataBound event

3 Answers 94 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
SSirica asked on 15 Oct 2010, 08:52 PM
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">
    <ItemTemplate>
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="width: 75px;">
                    <%#DataBinder.Eval(Container.DataItem, "line_number")%>
                </td>
                <td style="width: 200px; padding-left: 5px;">
                    <%#DataBinder.Eval(Container.DataItem, "line_description")%>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</telerik:RadComboBox>

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?

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 18 Oct 2010, 01:03 PM
If you're using the ItemTemplate, why not format it using the third parameter offered by the DataBinder.Eval method.

I hope that helps.
0
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
answered on 18 Oct 2010, 03:16 PM
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. 
0
Simon
Telerik team
answered on 25 Oct 2010, 01:41 PM
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.

Regards,
Simon
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
Tags
ComboBox
Asked by
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Cori
Top achievements
Rank 2
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Simon
Telerik team
Share this question
or