Solved

Details view not showing carriage returns

Posted on 2011-03-17
7
763 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 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