RadMaskedTextBox for null value

4 posts, 0 answers
  1. Tommy
    Tommy avatar
    10 posts
    Member since:
    Dec 2008

    Posted 09 Apr 2009 Link to this post

    Hi team:
               Now I have a grid which band a database tabe, in the grid have a "phone" column  as the follow code
    <telerik:GridTemplateColumn UniqueName="PhoneNumber" DataField="PhoneNumber"
                                            HeaderText="PPHONE" Visible="true" AllowFiltering="true" ReadOnly="true">
                                            <HeaderStyle HorizontalAlign="Center" Font-Bold="True" />
                                            <ItemTemplate>
                                                <telerik:RadMaskedTextBox ID="tboxPhoneNumber" runat="server"  Mask="(###) ###-#### x####"
                                                    NumericRangeAlign="Left" Text='<%#Bind("PhoneNumber") %>' ReadOnly="true" >
                                                </telerik:RadMaskedTextBox>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>

    but when the "PhoneNumber" field value is null, grid column  will show text "(___) ___-____x____",can you give me a hand I just want to show a empty string in the grid.
    Thanks.

    Tommy

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Apr 2009 Link to this post

    Hello Tommy,

    I tried following code snippet for achieving the scenario. Try the following code snippet in RadGrid_ItemDataBound event for removing the Mask for RadMaskedTextBoxes which have null value.

    CS:
     
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            RadMaskedTextBox text = (RadMaskedTextBox)item.FindControl("tboxPhoneNumber");  
            if (text.Text == String.Empty)  
            {  
                text.Mask = "";                  
            }  
        }  

    Thanks,
    Princy.
  3. Joe
    Joe avatar
    2 posts
    Member since:
    Jan 2009

    Posted 09 Apr 2009 Link to this post

    Princy, I have met the same problem. Your reply did help me a lot also. But what if the phone number is without extension number just like "(212) 158-1265 x____", how to remove the underline? I don't want to catch any underline in the grid whatever the phone numer is, not only for empty phone number.
    Thanks.
  4. Tommy
    Tommy avatar
    10 posts
    Member since:
    Dec 2008

    Posted 09 Apr 2009 Link to this post

    Hi Princy:
        As joe said I also have the same problem about the phone ext num,now I think use the follow code can dealwith this problem,
    but any good idea,can you give me.

     
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            RadMaskedTextBox text = (RadMaskedTextBox)item.FindControl("tboxPhoneNumber");  
            if (text.Text == String.Empty)  
            {  
                text.Mask = "";                  
            } 
            if (text.Text.Length <3+3+4)  
            {  
                text.Mask = "(###) ###-####";                  
            } 
    else
            {  
                text.Mask = "(###) ###-####x####";                  
            } 


        }  











Back to Top