?
Solved

Details view not showing carriage returns

Posted on 2011-03-17
7
Medium Priority
?
775 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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