Formatting and validating an asp:Literal control inside a DetailsView

mcluna

New Member
In a DetailsView one of the controls is a TextBox called PrimaryPhone.PrimaryPhone is formatted using string.Format in an ASP:literal control.The data is stored like this in the database:\[code\]9781231234\[/code\]It is using a Iif function to handle the formatting of 10 digit entries.\[code\]<asp:TemplateField HeaderText="Primary Phone:" SortExpression="PrimaryPhone"> <EditItemTemplate> <asp:TextBox ID="TextBoxPrimaryPhoneEdit" runat="server" Text='<%# Bind("PrimaryPhone") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBoxPrimaryPhoneInsert" runat="server" Text='<%# Bind("PrimaryPhone") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Literal ID="PrimaryPhoneLiteral" runat="server" Text='<%# iif(Len(Eval("PrimaryPhone"))=10, string.Format("{0:(###) ###-####}", Int64.Parse(Eval("PrimaryPhone").ToString())), Eval("PrimaryPhone")) %>' /> </ItemTemplate> <ItemStyle ForeColor="Blue" /></asp:TemplateField>\[/code\]Instead of the Iif function we would like to format the PrimaryPhone from a VB.Net code-behind file because the phone numbers could be:\[code\]10 digits 7 digits\[/code\]Some of the phone numbers are also missing.We would like to format it based on the length of the numbers entered into the PrimaryPhone DetailsView TextBox. We are looking to use a Case statement for this.Is it also possible to validate the entry of the phone number in the EditItemTemplate and the InsertItemTemplate and have an Ajax validation callout extender be displayed when the phone number is not 10 or 7 digits?Can you show the coding needed to format the PrimaryPhone from the code-behind file?
 
Back
Top