Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Details view not showing carriage returns

Posted on 2011-03-17
7
755 Views
Last Modified: 2012-06-27
Hi All,
I have my details view working with select, insert, edit and all that. They are set as templates.
My problem lies in that When I enter text in the insert or edit field it will show my carrige returns. But when I choose select for window of text the carriage returns do not show up in the text. Any ideas on how i can fix this? Thanks in advance.
<ContentTemplate>
        <asp:Button ID="btnShowpopup" runat="server" style="display:none;" />
        <cc1:ModalPopupExtender ID="mdlPopup" runat="server" 
            TargetControlID="btnShowPopup" PopupControlID="pnlPopup" 
            CancelControlID="btnClose" BackgroundCssClass="modalBackground" 
            DropShadow="True">
        </cc1:ModalPopupExtender>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataSourceID="Selection" Width="720px" CellPadding="4" ForeColor="#333333" 
        GridLines="None" onitemdeleted="DetailsView1_ItemDeleted" 
    onitemupdated="DetailsView1_ItemUpdated" onitemcommand="DetailsView1_ItemCommand" 
            ondatabound="DetailsView1_DataBound" FooterText="Test">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" Wrap="True" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <FooterTemplate>
         <asp:PlaceHolder ID="phCloseButton" runat="server">
    </asp:PlaceHolder>   
        </FooterTemplate>
        <Fields>
            <asp:BoundField DataField="SolutionID" HeaderText="ID" 
                InsertVisible="False" ReadOnly="True" SortExpression="SolutionID" >
            <HeaderStyle Height="20px" Width="100px" Font-Size="Small" />
            <ItemStyle Height="20px" Font-Size="Small" />
            </asp:BoundField>
            <asp:BoundField DataField="SoftwareType" HeaderText="Software" 
                SortExpression="SoftwareType" >
            <HeaderStyle Height="20px" Font-Size="Small" />
            <ItemStyle Height="20px" Font-Size="Small" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="Problem" SortExpression="Problem">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Problem") %>' Height="180px" Width="600px" TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Problem") %>' TextMode="MultiLine"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Problem") %>' TextMode="MultiLine"></asp:Label>
                </ItemTemplate>
                
                <ItemStyle />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Solution" SortExpression="Solution">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Solution") %>' Height="180px" Width="600px" TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Solution") %>' TextMode="MultiLine"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Solution") %>' TextMode="MultiLine"></asp:Label>
                </ItemTemplate>
                <ControlStyle />
            </asp:TemplateField>
            <asp:BoundField DataField="Date" DataFormatString="{0:d}" HeaderText="Date" 
                SortExpression="Date" >
            <HeaderStyle Height="20px" Font-Size="Small" />
            <ItemStyle Height="20px" Font-Size="Small" />
            </asp:BoundField>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text="Update" ></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                    <h3> Be Sure to Update or Cancel before Clicking Close button</h3>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Edit" OnClientClick="return confirm('OK to Update?');"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text="Delete" OnClientClick="return confirm('OK to Delete?');"></asp:LinkButton>
                    
                </ItemTemplate>
            </asp:TemplateField>
            
        </Fields>
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderTemplate>
        </HeaderTemplate>
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:DetailsView>
    <div class="footer">
      <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="False" style="display:none;"/>
    </div>
    
    </ContentTemplate>

Open in new window

0
Comment
Question by:EPSupport2
  • 5
  • 2
7 Comments
 
LVL 25

Assisted Solution

by:Rouchie
Rouchie earned 500 total points
ID: 35163242
You need to replace the item's carriage returns with HTML line breaks (the breaks currently show in source but aren't rendered by the browser):

Replace

 <asp:Label ID="Label1" runat="server" Text='<%# Bind("Problem") %>' TextMode="MultiLine"></asp:Label>

with

 <asp:Label ID="Label1" runat="server" Text='<%# Replace(Container.DataItem("Problem"), vbCrLf, "<br/>") %>' TextMode="MultiLine"></asp:Label>
0
 

Author Comment

by:EPSupport2
ID: 35164623
Thanks for the reply, but now I get the following errors:

Error      4      The name 'Replace' does not exist in the current context      C:\Default2.aspx      126      
Error      5      Non-invocable member 'System.Web.UI.IDataItemContainer.DataItem' cannot be used like a method.      C:\Default2.aspx      126
Error      6      The name 'vbCrLf' does not exist in the current context      C:\Default2.aspx      126      
      
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 35164767
Okay then maybe after the .DataBind() line of code, enumerate through the rows and change them...

		DetailsViewMode.DataSource = ....whatever
		DetailsViewMode.DataBind()


		If DetailsView1.CurrentMode = DetailsViewMode.ReadOnly Then
			For Each r As DetailsViewRow In DetailsView1.Rows
				Dim Label1 As Label = CType(r.FindControl("Label1"), Label)
				Label1.Text = Label1.Text.Replace(vbCrLf, "<br/>")
			Next
		End If

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:EPSupport2
ID: 35165125
Would you know the equivilant in C#?
0
 

Accepted Solution

by:
EPSupport2 earned 0 total points
ID: 35167756
Rouchie,
I have found the soultion for c# in case anyone else needs the answer. Thanks for pointing me in the right direction.
Replace :
<ItemTemplate>
 <asp:Label ID="Label1" runat="server" Text='<%# Bind("Problem") %>' TextMode="MultiLine"></asp:Label>
</ItemTemplate>

With:

<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# ((string)Eval("Problem")).Replace("\n", "<br>")%>' TextMode="MultiLine"></asp:Label>
</ItemTemplate>
0
 

Author Comment

by:EPSupport2
ID: 35167776
Okay to close
0
 

Author Closing Comment

by:EPSupport2
ID: 35196697
Code was requested in C#, but was answered in VB.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question