Solved

Details view not showing carriage returns

Posted on 2011-03-17
7
747 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now