Answered by:
Create a text delimited string of content and display separated text in control on page.

Question
-
User1909155429 posted
I display a message on page using the code below.
Dim msg As Message = CType(Session("Message"), Message)
FreeTextBox1.Text = Server.HtmlDecode(msg.Body)
What i want to do is display each bit of saved text in individual rows on page as read only content. While insert new text below content.
When saved the new text is added to the list of content and saved, ready to be displayed again in order of addition.
Thursday, July 16, 2020 2:39 PM
Answers
-
User348806598 posted
You can do this with repeater control-
<form id="form1" runat="server"> <asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <asp:TextBox runat="server" Text="<%# Container.DataItem %>" ReadOnly="true"></asp:TextBox><br /> </ItemTemplate> </asp:Repeater> <fieldset> New content: <asp:TextBox ID="txtNewData" runat="server"></asp:TextBox> <asp:Button ID="btnAddNew" runat="server" Text="Add new" OnClick="btnAddNew_Click" /> </fieldset> </form>
Friend Class SurroundingClass Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not Page.IsPostBack Then Session("Data") = "Text1|Text2|Text3" 'set initial data BindData() End If End Sub Private Sub BindData() rpt.DataSource = GetData() rpt.DataBind() End Sub Private Function GetData() As List(Of String) Return Session("Data").ToString().Split((New Char() {"|"c})).ToList() End Function Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As EventArgs) Dim data = GetData() data.Add(txtNewData.Text) Session("Data") = String.Join("|", data) BindData() End Sub End Class
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 16, 2020 3:57 PM
All replies
-
User348806598 posted
You can do this with repeater control-
<form id="form1" runat="server"> <asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <asp:TextBox runat="server" Text="<%# Container.DataItem %>" ReadOnly="true"></asp:TextBox><br /> </ItemTemplate> </asp:Repeater> <fieldset> New content: <asp:TextBox ID="txtNewData" runat="server"></asp:TextBox> <asp:Button ID="btnAddNew" runat="server" Text="Add new" OnClick="btnAddNew_Click" /> </fieldset> </form>
Friend Class SurroundingClass Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not Page.IsPostBack Then Session("Data") = "Text1|Text2|Text3" 'set initial data BindData() End If End Sub Private Sub BindData() rpt.DataSource = GetData() rpt.DataBind() End Sub Private Function GetData() As List(Of String) Return Session("Data").ToString().Split((New Char() {"|"c})).ToList() End Function Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As EventArgs) Dim data = GetData() data.Add(txtNewData.Text) Session("Data") = String.Join("|", data) BindData() End Sub End Class
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 16, 2020 3:57 PM -
User1909155429 posted
That looks great. although i have aditional problem ,my saved string contains identity values
FreeTextBox1.Text = Server.HtmlDecode("Original Message<hr/> From: " & msg.SenderId & msg.Body)
i would also like to delimiter the identity value and place above body text. so user knows who it is.
Thanks
Thursday, July 16, 2020 9:12 PM -
User-1330468790 posted
Hi peterthegreat,
Have you solved the problem now?
It looks like the additional problem is adding the identity values. However, it is not very clear.
Could you please specify what the problem is?
Thank you very much.
Best regards,
Sean
Monday, July 20, 2020 11:09 AM