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

Format Telephone in Column from nvarchar db

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 31 Dec 2014, 03:58 PM
I have a database nvarchar field which stores the phone number.  I would like to add a column in the grid to display the formatted phone number and add a hyperlink.  Some of the cellphone fields can be null, so I am trying to check for that before converting to Int64.

The error I am getting is The best overloaded method match for 'string.IsNullOrWhiteSpace(string)' has some invalid arguments.  If I set the ItemTemplate to just Eval("CellPhone") the grid properly displays the cellphone numbers as an unformatted string.

What is the best approach here?  Once I get the basic ItemTemplate working, I was going to try to add a hyperlink so users can click on the phone number and invoke the dialing app.  ie. tel://2055551234 


<telerik:GridTemplateColumn DataField="CellPhone" FilterControlAltText="Filter CellPhoneNumber column" HeaderText="Cell Phone" UniqueName="CellPhoneNumber">
 
    <ItemTemplate>
        <%#  !string.IsNullOrWhiteSpace(Eval("CellPhone")) ? string.Format("{0:(###)###-####}", Convert.ToInt64(Eval("CellPhone"))) : "" %>
    </ItemTemplate>
 
</telerik:GridTemplateColumn>

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Jan 2015, 09:46 AM
Hello Michael,

The reason for the error you are seeing is that Eval returns an object, however a string should be passed to IsNullOrWhiteSpace. In order to remedy the issue you should use the following:

string.IsNullOrWhiteSpace(Eval("CellPhone").ToString())

This way you would be able to display the phone in the correct format. Now, to enable the user to click on the number and open an external application you can use a HyperLink. Check out the following code-snippet that illustrates the approach:

<telerik:GridTemplateColumn DataField="CellPhone" HeaderText="CellPhone" UniqueName="CellPhone">
    <ItemTemplate>
        <asp:HyperLink runat="server" ID="HyperLink1"
            Text='<%#  !string.IsNullOrWhiteSpace(Eval("CellPhone").ToString()) ? string.Format("{0:(###)###-####}", Convert.ToInt64(Eval("CellPhone"))) : "" %>'
            NavigateUrl='callto:<%#  !string.IsNullOrWhiteSpace(Eval("CellPhone").ToString()) ? string.Format("{0:(###)###-####}", Convert.ToInt64(Eval("CellPhone"))) : "" %>' />
         
    </ItemTemplate>
</telerik:GridTemplateColumn>



Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or