locked
how to split in next line within one row in repeater control in asp.net RRS feed

  • Question

  • User1878568433 posted

    My Inline code : 

    <asp:UpdatePanel ID="UP1" runat="server">
    <ContentTemplate>
    <table class="border-collapse table-hp">
    <asp:Repeater ID="rpDenialCommentInfo" ClientIDMode="Static" runat="server">
    <HeaderTemplate>
    </table>
    <table class="border-collapse table-hp">
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td>
    <div class="cards-even">
    <div>
    <asp:Label ID="lblComments" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "vc_denial_comments")%>'></asp:Label>
    </div>
    </div>
    </td>
    </tr>
    </ItemTemplate>
    <AlternatingItemTemplate>
    <tr>
    <td>
    <div class="cards-even">
    <div>
    <asp:Label ID="lblComments" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "vc_denial_comments")%>'></asp:Label>
    </div>
    </div>
    </td>
    </tr>
    </AlternatingItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
    </asp:Repeater>
    <tr id="trComment" runat="server" visible="false">
    <td>
    <div class="cards-even">
    <div>
    <asp:Label ID="lblHeaderComment1" runat="server"></asp:Label>
    </div>
    </div></td>
    </tr>
    </table>
    </ContentTemplate>
    </asp:UpdatePanel>

    Code Behind: 

    Private Sub ShowDenialComments()
    Dim ds As DataSet = New DataSet()
    Dim ObjTicketInfo As BO.TicketInfo = New BO.TicketInfo()
    ObjTicketInfo.ClaimNumber = CType(Request.QueryString("ClaimNumber").Trim(), Integer)
    ObjTicketInfo.ClientID = CType(Request.QueryString("ClientID").Trim(), Integer)

    Dim BlTicketInfo As BL.GetTicketInfo = New BL.GetTicketInfo()
    ds = BlTicketInfo.GetDenialCommentInformation(ObjTicketInfo)

    If (ds.Tables(0).Rows.Count > 0) Then
    rpDenialCommentInfo.DataSource = ds.Tables(0)
    rpDenialCommentInfo.DataBind()
    Else
    rpDenialCommentInfo.DataSource = Nothing
    rpDenialCommentInfo.DataBind()
    End If
    End Sub

    Now my data is showing in Repeater Control Like this : 

    CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018

    But I want like this within one row only split in new line: CPT is denied - 06/09/2018 |

                                                                                                   CPT is denied becoz of abc reasin - 06/09/2018 |

                                                                                                   Some Text - 06/09/2018

    Please help ASAP. It is Urgent

    Friday, September 7, 2018 5:33 AM

Answers

  • User-893317190 posted

    Hi sripadasatpathy,

    You could format your data in repeater's  OnItemDataBound event.

    Below is my code.

    <head runat="server">
        <title></title>
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
        <style>
            .cards-even{background-color:lightblue}
            .cards-odd{background-color:lightcoral}
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UP1" runat="server">
                <ContentTemplate>
                    <table class="border-collapse table-hp">
                        <asp:Repeater ID="rpDenialCommentInfo" ClientIDMode="Static" runat="server" OnItemDataBound ="rpDenialCommentInfo_ItemDataBound">
                            <HeaderTemplate>
                                </table>
                                <table class="border-collapse table-hp">
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <div class="cards-odd">
                                            <div>
                                                <asp:Label ID="lblComments" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "vc_denial_comments")%>'></asp:Label>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <AlternatingItemTemplate>
                                <tr>
                                    <td>
                                        <div class="cards-even">
                                            <div>
                                                <asp:Label ID="lblComments" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "vc_denial_comments")%>'></asp:Label>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </AlternatingItemTemplate>
                            <FooterTemplate>
                            </FooterTemplate>
                        </asp:Repeater>
                        <tr id="trComment" runat="server" visible="false">
                            <td>
                                <div class="cards-even">
                                    <div>
                                        <asp:Label ID="lblHeaderComment1" runat="server"></asp:Label>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>

    Code behind.

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            If Not IsPostBack Then
                Dim models As List(Of Model) = New List(Of Model)() From {
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    }
                }
                rpDenialCommentInfo.DataSource = models
                rpDenialCommentInfo.DataBind()
            End If
    
    
        End Sub
    
        Protected Sub rpDenialCommentInfo_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                ' get the content of of property  vc_denial_comments
                Dim content As String = TryCast(DataBinder.Eval(e.Item.DataItem, "vc_denial_comments"), String)
                Dim commentsLabel As Label = TryCast(e.Item.FindControl("lblComments"), Label)
                ' split the content with | and join the splited content with  |<br> to make new lines
                commentsLabel.Text = String.Join("|<br/>", content.Split("|"))
    
            End If
    
        End Sub
    End Class
    
    Public Class Model
        Public Property vc_denial_comments As String
    End Class
    

    The result.

    As you haven't provided what is the structure of your table from database , if  I misunderstand what you mean, please give more information about your table and your object ObjTicketInfo,BlTicketInfo .

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2018 2:45 AM

All replies

  • User-893317190 posted

    Hi sripadasatpathy,

    You could format your data in repeater's  OnItemDataBound event.

    Below is my code.

    <head runat="server">
        <title></title>
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
        <style>
            .cards-even{background-color:lightblue}
            .cards-odd{background-color:lightcoral}
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UP1" runat="server">
                <ContentTemplate>
                    <table class="border-collapse table-hp">
                        <asp:Repeater ID="rpDenialCommentInfo" ClientIDMode="Static" runat="server" OnItemDataBound ="rpDenialCommentInfo_ItemDataBound">
                            <HeaderTemplate>
                                </table>
                                <table class="border-collapse table-hp">
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <div class="cards-odd">
                                            <div>
                                                <asp:Label ID="lblComments" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "vc_denial_comments")%>'></asp:Label>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <AlternatingItemTemplate>
                                <tr>
                                    <td>
                                        <div class="cards-even">
                                            <div>
                                                <asp:Label ID="lblComments" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "vc_denial_comments")%>'></asp:Label>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </AlternatingItemTemplate>
                            <FooterTemplate>
                            </FooterTemplate>
                        </asp:Repeater>
                        <tr id="trComment" runat="server" visible="false">
                            <td>
                                <div class="cards-even">
                                    <div>
                                        <asp:Label ID="lblHeaderComment1" runat="server"></asp:Label>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>

    Code behind.

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            If Not IsPostBack Then
                Dim models As List(Of Model) = New List(Of Model)() From {
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    },
                    New Model With {
                        .vc_denial_comments = "vc_denial_comments=CPT is denied - 06/09/2018 | CPT is denied becoz of abc reasin - 06/09/2018 | Some Text - 06/09/2018"
                    }
                }
                rpDenialCommentInfo.DataSource = models
                rpDenialCommentInfo.DataBind()
            End If
    
    
        End Sub
    
        Protected Sub rpDenialCommentInfo_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                ' get the content of of property  vc_denial_comments
                Dim content As String = TryCast(DataBinder.Eval(e.Item.DataItem, "vc_denial_comments"), String)
                Dim commentsLabel As Label = TryCast(e.Item.FindControl("lblComments"), Label)
                ' split the content with | and join the splited content with  |<br> to make new lines
                commentsLabel.Text = String.Join("|<br/>", content.Split("|"))
    
            End If
    
        End Sub
    End Class
    
    Public Class Model
        Public Property vc_denial_comments As String
    End Class
    

    The result.

    As you haven't provided what is the structure of your table from database , if  I misunderstand what you mean, please give more information about your table and your object ObjTicketInfo,BlTicketInfo .

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2018 2:45 AM
  • User1878568433 posted

    Thanks a lot. It works for me

    Tuesday, September 11, 2018 7:17 AM