•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 429,966 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,602 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 3981 | Replies: 8 | Solved
![]() |
•
•
Join Date: Mar 2007
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
hi..i'm new in using ASP.NET application. Please guide me as i've only about 30% knowledge on developing web application in .NET
ok..my problem is..
i have a textbox..
i wanted user to create multiple option by entering each option per line in the textbox...
in other words..if user want to enter 4 option, 1st option will be at 1st line, 2nd option at 2nd line....and so on..
so..when i create button "Submit"..it will automatically assume that data in the first line will be inserted to first row in table in my database...
can this be done? please somebody help me...
ok..my problem is..
i have a textbox..
i wanted user to create multiple option by entering each option per line in the textbox...
in other words..if user want to enter 4 option, 1st option will be at 1st line, 2nd option at 2nd line....and so on..
so..when i create button "Submit"..it will automatically assume that data in the first line will be inserted to first row in table in my database...
can this be done? please somebody help me...
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation:
Rep Power: 7
Solved Threads: 59
Consider using a ListBox web control.
1. You supply the options for the user to choose rather than free type (free text is always a validation headache for you to keep sh** out of your db)
2. ListBox has a multiselect mode (user can use shift or ctrl key to select more than one option if you set the property to true)
3. You can iterate the ListBox as it implements IEnumarable, which has gotta be easier than parsing a fat wedge of text from a textarea (which is what a multiline textbox is rendered as to the client)
Example code:
the aspx page
the code behind
1. You supply the options for the user to choose rather than free type (free text is always a validation headache for you to keep sh** out of your db)
2. ListBox has a multiselect mode (user can use shift or ctrl key to select more than one option if you set the property to true)
3. You can iterate the ListBox as it implements IEnumarable, which has gotta be easier than parsing a fat wedge of text from a textarea (which is what a multiline textbox is rendered as to the client)
Example code:
the aspx page
asp Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:ListBox ID="lstOptions" runat="server" SelectionMode="Multiple"> <asp:ListItem Value="Option1" Text="Option1"></asp:ListItem> <asp:ListItem Value="Option2" Text="Option2"></asp:ListItem> <asp:ListItem Value="Option3" Text="Option3"></asp:ListItem> <asp:ListItem Value="Option4" Text="Option4"></asp:ListItem> </asp:ListBox> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /> <br /> <asp:Repeater ID="rprChoices" runat="server"> <HeaderTemplate><ul></HeaderTemplate> <ItemTemplate><li><%# Container.DataItem %></li></ItemTemplate> <FooterTemplate></ul></FooterTemplate> </asp:Repeater> </div> </form> </body> </html>
the code behind
csharp Syntax (Toggle Plain Text)
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Specialized; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { //declare an array to hold the selected options StringCollection options = new StringCollection(); //iterate through the list items in the list box foreach (ListItem item in lstOptions.Items) { //if the item was selected by the user this //store it in our array if(item.Selected) options.Add(item.Value); } //I am merely confirming the choices back to the client //this is where you would save the contents of options //to your database. rprChoices.DataSource = options; rprChoices.DataBind(); } } ;
Last edited by hollystyles : Mar 29th, 2007 at 3:32 pm. Reason: Add code example
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation:
Rep Power: 7
Solved Threads: 59
•
•
•
•
can u write in vb.net?
Yes thanks, but personally I find typing VB syntax akin to scraping honey off a teaspoon, whereas typing c# syntax is more like licking it off! IYKWIM.
for example:
csharp Syntax (Toggle Plain Text)
StringCollection options = new StringCollection(); //MMMm MMmm baby!
vbnet Syntax (Toggle Plain Text)
Dim options As New StringCollection() 'wordy wordy yuck!
•
•
Join Date: Mar 2007
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
aiyak..
but what if i want user to enter their choices...
my program is like...
i want to create a survey creator system..
user will enter their question..1 question may have more than 1 answers...
i want user to enter their choices..one question per line, then i'm gonna save the option line by line as list of options into my database b4 the system generate the template..
so..right now, my problem is to reaa line by line text in the textbox..and to save the list of options into database..
can u help me?
but what if i want user to enter their choices...
my program is like...
i want to create a survey creator system..
user will enter their question..1 question may have more than 1 answers...
i want user to enter their choices..one question per line, then i'm gonna save the option line by line as list of options into my database b4 the system generate the template..
so..right now, my problem is to reaa line by line text in the textbox..and to save the list of options into database..
can u help me?
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation:
Rep Power: 7
Solved Threads: 59
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.
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.
asp Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" Width="280" MaxLength="128"></asp:TextBox> <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" /> <br /> <asp:ListBox ID="lstOptions" runat="server" SelectionMode="Multiple" Width="280"></asp:ListBox> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /> <asp:Repeater ID="rprChoices" runat="server"> <HeaderTemplate><ul></HeaderTemplate> <ItemTemplate><li><%# Container.DataItem %></li></ItemTemplate> <FooterTemplate></ul></FooterTemplate> </asp:Repeater> </div> </form> </body> </html>
csharp Syntax (Toggle Plain Text)
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Specialized; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { //declare an array to hold the selected options StringCollection options = new StringCollection(); //iterate through the list items in the list box foreach (ListItem item in lstOptions.Items) { //store it in our array options.Add(item.Value); } //I am merely confirming the choices back to the client //this is where you would save the contents of options //to your database. rprChoices.DataSource = options; rprChoices.DataBind(); } protected void btnAdd_Click(object sender, EventArgs e) { if (TextBox1.Text != string.Empty) { lstOptions.Items.Add(new ListItem(TextBox1.Text, TextBox1.Text)); TextBox1.Text = string.Empty; } } }
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Reading line breaks in a textbox (Visual Basic 4 / 5 / 6)
Other Threads in the ASP.NET Forum
- Previous Thread: Welcome User Feature from Access DB
- Next Thread: Forgotton Password feature from an Access DB



Linear Mode