Solved

Details view not showing carriage returns

Posted on 2011-03-17
7
751 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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