RSS Forums RSS
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

separating line by line from textbox with textmode=multiline

Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,166
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 59
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: separating line by line from textbox with textmode=multiline

  #7  
Mar 30th, 2007
Oh dear, fussy fussy :cheesy:

Ok I add a TextBox for the user to add their free text and an add button that adds there text to the ListBox on postback.

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12. <asp:TextBox ID="TextBox1" runat="server" Width="280" MaxLength="128"></asp:TextBox>
  13. <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
  14. <br />
  15. <asp:ListBox ID="lstOptions" runat="server" SelectionMode="Multiple" Width="280"></asp:ListBox>
  16. <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
  17.  
  18. <asp:Repeater ID="rprChoices" runat="server">
  19. <HeaderTemplate><ul></HeaderTemplate>
  20. <ItemTemplate><li><%# Container.DataItem %></li></ItemTemplate>
  21. <FooterTemplate></ul></FooterTemplate>
  22. </asp:Repeater>
  23. </div>
  24. </form>
  25. </body>
  26. </html>

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Collections.Specialized;
  11.  
  12. public partial class _Default : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16.  
  17. }
  18. protected void btnSubmit_Click(object sender, EventArgs e)
  19. {
  20. //declare an array to hold the selected options
  21. StringCollection options = new StringCollection();
  22.  
  23. //iterate through the list items in the list box
  24. foreach (ListItem item in lstOptions.Items)
  25. {
  26. //store it in our array
  27. options.Add(item.Value);
  28. }
  29.  
  30. //I am merely confirming the choices back to the client
  31. //this is where you would save the contents of options
  32. //to your database.
  33. rprChoices.DataSource = options;
  34. rprChoices.DataBind();
  35. }
  36. protected void btnAdd_Click(object sender, EventArgs e)
  37. {
  38. if (TextBox1.Text != string.Empty)
  39. {
  40. lstOptions.Items.Add(new ListItem(TextBox1.Text, TextBox1.Text));
  41. TextBox1.Text = string.Empty;
  42. }
  43. }
  44. }
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:26 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC