blogspot visit counter

Wednesday, 15 May 2013

listbox multiple selection asp.net

listbox multiple selection asp.net
Introduction : -

A ListBox control provides an interface to display a list of items. Users can select one or more items from the list. A ListBox may be used to display multiple columns and these columns may have images and other controls.
In this tutorial, we will learn how to create a ListBox control at design-time as well as at run-time. We will also see how to create a multiple-column ListBox control with single and multiple selections. This article also covers most of the properties and methods of the ListBox control.

Description :-
 
This example shows the basics on how to save multiple selected items from the ASP.Net ListBox control to the database in ASP.Net. Please note that this example requires a basic knowledge of ADO.NET.

STEP1: Setting up the User Interface (GUI)

For the simplicity of this demo, I just set up the web form like below:



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #form1
        {
            text-align: center;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        Employee names: <br />

        <asp:ListBox ID="ListBox1" runat="server" Height="149px" SelectionMode="Multiple" Width="113px">

        <asp:ListItem>chitranjan</asp:ListItem>

        <asp:ListItem>ranjan</asp:ListItem>

        <asp:ListItem>Rohan</asp:ListItem>

        <asp:ListItem>Shohan</asp:ListItem>

        <asp:ListItem>Ronak</asp:ListItem>

        <asp:ListItem>Ranu</asp:ListItem>

        <asp:ListItem>Raja</asp:ListItem>

        <asp:ListItem>Papu</asp:ListItem>

        </asp:ListBox>  

    </div>

    <br />

    <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" />
    </form>
</body>
</html>

Notes: 

* Since the ListBox is intended for multiple item selections then we need to set the SelectionMode attribute of the ListBox to Multiple

* To do multiple Selections in the ListBox then just hold Ctrl key and select the items you want.
STEP 2: Creating a Simple Database Table

In this demo, we are going to store the selected employee names that is selected from the ListBox to the database. So let's now create a simple table that contains the following Column Names:
Note [-id  is auto increment]





Note: I set the Id to auto increment so that the id will be automatically generated for every new added row. To do this select the Column name “Id” and in the column properties set the “Identity Specification” to yes.

STEP 3: Declaring the necessary name spaces:

Be sure to add the following namespaces below:



using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Text;



We need to declare the namespaces above so that we can use the SqlClient, StrngCollections and StringBuilder built-in methods in our codes later.

STEP4: Creating the Method for Multiple Inserts.

Here are the code blocks below:



protected void Button1_Click(object sender, EventArgs e)
    {
        StringCollection sc = new StringCollection();
        foreach (ListItem item in ListBox1.Items)
        {

            if (item.Selected)
            {

                sc.Add(item.Text);

            }

        }

        InsertRecords(sc);
    }


    private void InsertRecords(StringCollection sc)
    {
        SqlConnection conn = VoterConnectionDB.GetConnection();
        StringBuilder sb = new StringBuilder(string.Empty);
        foreach (string item in sc)
        {

            //For pass the more than one column then use this format
            const string sqlStatement = "INSERT INTO Table1 (city,contactno,Employees) VALUES";
            sb.AppendFormat("{0}('{1}','{2}','{3}');",sqlStatement,"indore","0000000000", item);
           // sb.AppendFormat("{0}('{1}','{2}','{3}');", sqlStatement, sqlStatement[0], sqlStatement[1], item);
           // sb.AppendFormat("{0}('{1}','{2}','{3}');", sqlStatement, txtcity_txt, txt_contact.Text, item);
        }

        try
        {
         SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Records Successfuly Saved!');", true);
        }

        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            conn.Close();
        }

    }

STEP5: Compile and Run the Application.

The page output would look something like below:

On Run Time


 On Selection The Name From the ListBox And Press Save Button

Genrate the Pupop After Insert The Record In the database image as shown below




Download sample code attached






WCF Service Example Step By Step For Beginners

85 comments:

  1. very usefull notes and we need more information on this topic please post updated data . thanks for your post.
    Dot net online tutorials


    ReplyDelete
    Replies
    1. Thank ' s for your comment.New information on this topic is coming soon..

      Delete
  2. This post is very Nice and Clear for use multiple selection of list box .i am very happy for your post. please provide more example related to this post

    ReplyDelete
  3. Besant Tech Reviews,

    This page is dedicated for our Besant Technologies Reviews by our students. Please give your reviews here,

    Besant Technologies Reviews

    ReplyDelete

  4. This page is dedicated for our Besant Technologies Reviews by our students. Please give your
    reviews here,

    Besant Technologies Reviews

    ReplyDelete
  5. This page is dedicated for our Besant Technologies Reviews by our students. Please give your reviews here,

    Besant Technologies Reviews

    ReplyDelete
  6. i read this blog i didn't have any knowledge about this but now i got some knowledge so keep on sharing such kind of an interesting blogs.



    Weblogic Application Server training

    ReplyDelete

  7. Really It's A Great Pleasure reading your Article,learned a lot of new things,we have to keep on updating it,Immediate Care in Chicago.By getting them into one place.Really thanks for posting.Very Thankful for the Informative Post.Really Thanks For Posting.

    ReplyDelete
  8. Good article. It is very useful for me to learn and understand easily USMLE Thanks for posting.

    ReplyDelete
  9. This Blog Provides Very Useful and Important Information. I just Want to share this blog with my friends and family members. Salesforce Certification Training

    ReplyDelete
  10. Brilliant post. The information I have been searching precisely. It helped me a lot, thanks. Keep coming with more such informative article. Would love to follow them. sap abap online training videos

    ReplyDelete
  11. Thanks For Such an useful and Important Information...

    Visakhapatnam Real Estate

    ReplyDelete
  12. I found the information on your website very useful.Visit Our 3 bhk Flats in Hyderabad
    Visit Our Reviews Aditya constructions Reviews

    ReplyDelete
  13. A very good article. Thanks to the author. I know what you need now is paper writing service .

    ReplyDelete
  14. Very useful information for people, I think this is what everyone needs. I know what you need is argument topics .

    ReplyDelete
  15. Great and useful article. Creating content regularly is very tough. Your points are motivated me to move on.
    https://writepaperfor.me/

    ReplyDelete
  16. To have more enhanced results and optimized benefits, you are able to take the help of experts making a call at QuickBooks Payroll Support Number
    Well! If you’re not in a position to customize employee payroll in.

    ReplyDelete
  17. Our Professionals have designed services in a competent means in order that they will offer you the required ways to the shoppers. we now have a tendency to at QuickBooks client Service are accessible 24*7 you just need to call our QuickBooks Customer Support Number which can be found in the marketplace on our website.

    ReplyDelete
  18. Our experts team at QuickBooks Payroll Support Phone Number is going to make you realize its advanced functions and assists anyone to lift up your business growth.

    ReplyDelete
  19. You'll need never to worry most likely as you are seeking help beneath the guidance of supremely talented and skilled support engineers that leave no stone unturned to land you of all of the errors which are part and parcel of QuickBook Customer Support Number.

    ReplyDelete
  20. To acquire a mistake free accounting experience, our QuickBooks Enterprise Support Phone Number team is here now to permit you focus on your organization growth in host to troubleshooting the accounting errors.

    ReplyDelete
  21. When it comes to rectification regarding the issue call Quickbooks Support Phone Number is can really help the Quickbooks users are right people to pin point and fix the matter completely. They assure resolution into the minimum wait time that saves your time.

    ReplyDelete
  22. We have been giving you some manual ways to fix this dilemma. However, it is convenient and safe to call at QuickBooks Tech Support Phone Number and let our technical experts use the troubleshooting pain to prevent the wastage of the precious time and cash.

    ReplyDelete
  23. Whatever the issue is, if it bothers you and deters the performance of your respective business, you may need to not get back seat and offer up, just dial us at our toll-free QuickBooks Support Number and luxuriate in incredible customer care.

    ReplyDelete
  24. It's simple to get a quantity of benefits with QuickBooks Support Phone Number. Proper analyses are done first. The experts find out from the nature associated with trouble. You'll get a whole knowledge as well.

    ReplyDelete
  25. We've been here to enhance your understanding in regards to the payroll updates happens in QuickBooks Payroll Support Phone Number, desktop, pro, premier 2019 versions. Solve your queries related to QuickBooks Online Payroll whether Enhanced or Full Service.

    ReplyDelete
  26. Options now contain QuickBooks Technical Support Number
    versions for manufacturers, wholesalers, professional firms, contractors and non-profit entities. And retailers, in adding to one precisely created for professional accounting firms who service numerous small enterprise clients.

    ReplyDelete
  27. QuickBooks Support Number, we have a group this is certainly focused and resilient to present uninterrupted Quickbooks Premier Technical Support contact number to all the its customers. You can easily contact our QuickBooks Support team without the hesitation at our Quickbooks tech support team contact number and land yourself out of every QuickBooks Premier issue. There could be a few regularly occurring errors that will assist you to determine your own personal issue. Let’s check out them.

    ReplyDelete
  28. The deep real cause is likely to be found out. Each of the clients are extremely satisfied with us. We have many businessmen who burn off our QuickBooks Help Phone Number.

    ReplyDelete
  29. In this web site, we will enable you to experience to create and put up the checklist for employee payment. To have more enhanced results and optimized benefits, you'll be able to take assistance from experts making a call at QuickBooks Payroll Support Number .

    ReplyDelete
  30. This accounting software program is compatible even in the Macintosh operating system and users can enjoy all the features given by downloading it. This software can also be used on iPhone through the QuickBooks Enterprise Support Phone Number for iOS users.

    ReplyDelete
  31. Might you run a business? Can it be way too hard to manage all? You need a hand for support. QuickBooks Payroll Support Number is an answer. If you wish to accomplish this through QuickBooks, you receive several advantages.

    ReplyDelete
  32. Hope now you realize that how exactly to connect with QuickBooks Enterprise Support. We have been independent alternative party support company for intuit QuickBooks, we would not have virtually any link with direct QuickBooks, the employment of name Images and logos on website only for reference purposes only.

    ReplyDelete
  33. QuickBooks Desktop Support Window at our toll-free.We at QuickBooks Tech Support Number are here for you really to help you get rid of technical issues in QuickBooks into the most convenient way. Our at any hour available QuickBooks Desktop Support help is accessible on just a call at our toll-free that too of many affordable price.

    ReplyDelete
  34. QuickBooks offers a number of features to trace your startup business. Day by day it is getting popular amonst the businessmen and entrepreneurs. But with the increasing popularity, QuickBooks is meeting a lot of technical glitches. And here we show up with our smartest solutions. Have a look at the problem list and once you face any of them just call Intuit QuickBooks Support for the assistance.

    ReplyDelete
  35. You can easily proceed with the previously listed steps carefully to eradicate this login issue. However, this is the wisest choice to call at 247 toll-free amount of QuickBooks to have in contact with certainly one of our technical experts at QuickBooks Enterprise Support Phone Number for a quick resolution of every issues in QBO.

    ReplyDelete
  36. Without taking most of your time, our team gets you rid of all unavoidable errors of this software. https://www.fixaccountingerror.com/ Would you like to Update QuickBooks Pro? We now have was able to make it simple for you at QuickBooks Pro Support contact number

    ReplyDelete
  37. The help of certified professionals Attentive customer executives Closing ability
    Dial our number to get in touch with our at QuickBooks Support. technical specialists available twenty-four hours a day.

    ReplyDelete
  38. In that case, Quickbooks online payroll support number provides 24/7 make it possible to our customer. Only you must do is make an individual call at our toll-free QuickBooks Payroll Support Phone Number . You could get resolve all of the major issues include installations problem, data access issue, printing related issue, software setup, server not responding error etc with our QuickBooks payroll support team.

    ReplyDelete
  39. Intuit has developed QuickBooks Payroll Support Phone Number program form with almost evolution to carry out all checks and taxes issues. Since no body is well in this globalization. Quite often when folks are protesting about incorrect calculation and defaults paychecks results. Similarly fixing QuickBooks structure of account could be a confusing try to do and difficult to handle all those for a normal user.

    ReplyDelete
  40. Instead of reopening the software, you should restart your computer and then you should try to open the QuickBooks Support Phone Number USA software. Although, this is not the permanent solution to get rid of this error you can easily .

    ReplyDelete
  41. Will you be facing the issue with decision making? The amount of is it possible to earn in a month? You ought to predict this before. Many people are not used to this. We shall help most of the folks. What business are you having? Can it be raw material business? Would you cope with retail trade? Craftsmen also cope with your selection of revenue. Sometimes you do not forecast the specific budget. We now have experienced individuals to provide you with the figure. We're going to also supply you with the figure of your respective budget which you yourself can get in the future from now. This will be only possible with QuickBooks Community Support.

    ReplyDelete
  42. Solving the Quickbooks related problems and issue Remotely . QuickBook Support Phone Number in current time is Number #1 accounting software popular in the USA , Canada , Europe and Australian market for business management.

    ReplyDelete
  43. Would you like to Update QuickBooks Pro? We now have was able to make it simple for you at QuickBooks Toll Free Phone Number. It is almost always simpler to focus on updated version as it helps you incorporate all of the latest features in your software and assists you undergo your task uninterrupted. You will find simple steps that you must follow. Firstly, click on file and choose the chance Open & Restore. Now open the file and click on Update Company File for New Version. And now maybe you are all set.

    ReplyDelete
  44. QuickBooks Payroll has emerged one of the better accounting software that has had changed this is of payroll. QuickBooks Payroll Tech Support Number will be the team that provide you Quickbooks Payroll Support. This software of QuickBooks comes with various versions and sub versions. Online Payroll and Payroll for Desktop may be the two major versions and they're further bifurcated into sub versions. Enhanced Payroll and Full-service payroll are encompassed in Online Payroll whereas Basic, Enhanced and Assisted Payroll come under Payroll for Desktop.

    ReplyDelete
  45. Quickbooks Support For Business All of the above has a particular use. People working with accounts, transaction, banking transaction need our service. Some QuickBook Support phone Number are employing excel sheets for a few calculations

    ReplyDelete
  46. Now you can get a sum of benefits with QuickBooks Technical Support Proper analyses are done first. The experts find out of the nature associated with trouble. You will definately get a complete knowledge as well. The support specialist will identify the problem.

    ReplyDelete
  47. With the quick response of Contact HP Printer Support of expert to customer, there is zero chance to stay in touch with issue more and more.

    ReplyDelete
  48. QuickBooks Payroll Technical Support executives for QuickBooks, we assure our twenty-four hours a day availability at our technical contact number.

    ReplyDelete
  49. QuickBooks Payroll Support Phone Number Customer Care Contact Number: Designed For every QuickBooks Version
    Comprises of an attractive lot of accounting versions, viz., QuickBooks Pro, QuickBooks Premier, QuickBooks Enterprise, QuickBooks POS, QuickBooks Mac, QuickBooks Windows, and QuickBooks Payroll, QuickBooks is becoming a dependable accounting software that one may tailor depending on your industry prerequisite.

    ReplyDelete
  50. QuickBooks Customer Support Number Services provide answers to all your valuable QuickBooks problem and in addition assists in identifying the errors with QuickBooks data files and diagnose them thoroughly before resolving these issues.

    ReplyDelete
  51. The support team at our end is very helpful in terms of handling the issues that pop up in QuickBooks Payroll Support Phone Number or several of its versions. When it comes to problems, every one us know that they are inevitable.

    ReplyDelete
  52. Problems are inevitable plus they usually do not come with a bang. Our team at QuickBooks Support Number is ready beforehand to provide you customer-friendly assistance if you speak to an issue using QuickBooks Pro. All of us is skilled, talented, knowledgeable and spontaneous. Without taking most of your time, our team gets you rid of all unavoidable errors of this software.

    ReplyDelete
  53. QuickBooks is accounting software, which is a cloud-based application produced by Inuit Inc. In fact, the application has been developed with the intention of keeping a safe record of financial needs for the business and QuickBooks Payroll Support help you in this. Additionally, it is a user-friendly accounting software; an easy task to maintain; assisting the company in keeping the records of financial transactions, and a whole lot more features.

    ReplyDelete
  54. Well! If you’re not able to customize employee payroll in QuickBooks Payroll Support Number and in addition result in the list optimally, in QB and QB desktop, then browse the description ahead.

    ReplyDelete
  55. It is possible to call us at QuickBooks Enterprise Support Phone Number , when you ever face any difficulty while using the this software.

    ReplyDelete
  56. Problems are inevitable and they also usually do not come with a bang. Our team at QuickBooks Pro Support contact number is ready beforehand to provide you customer-friendly assistance if you talk to an issue using QuickBooks Support Number Pro. Most of us is skilled, talented, knowledgeable and spontaneous. Without taking most of your time, our team gets you rid of most unavoidable errors of this software.

    ReplyDelete
  57. QuickBooks software helps the businesses to run smoothly either small size business or mid size businesses.QuickBooks also helps you with your confusions by just contacting our QuickBooks Enterprise Support Number +1-833-400-1001.This software provides you the best possible assistance and keeps you updated about each and every details about your business. Further we are available 24/7 for your help for any kind of assistance you just need to contact our QuickBooks Enterprise Support +1-833-400-1001. QuickBooks regularly updates itself according to the requirements of the users and we are always ready to add more features to help you in more and more convenient ways so that you can run your business smoothly and grow your business . This is our basic and most important concern about the QuickBooks users , help the QuickBooks users and create a healthy environment for them to run and grow their business smoothly . In any case you need our help you are welcome to contact our QuickBooks team by calling us on QuickBooks Enterprise Support Phone Number +1-833-400-1001.We are at your service 24/7 feel free to contact us regarding any issue regarding QuickBooks.

    ReplyDelete
  58. Intuit thrown QuickBooks Enterprise Solutions for medium-sized businesses. QuickBooks Enterprise Support Phone Number here to make tech support team to users. In September 2005, QuickBooks acquired 74% share connected with market in america.

    ReplyDelete
  59. Needless to say, QuickBooks Tech Support Number is certainly one among the list of awesome package within the company world. The accounting area of the a lot of companies varies based on this package. You will find so many fields it covers like creating invoices, managing taxes, managing payroll etc.

    ReplyDelete
  60. There you'll need QuickBooks Tech Support Phone Number for QuickBooks Pro-advisors, the certified experts with tremendous experience working on QuickBooks errors and Data damage related issues. Dial QuickBooks Help Number for complete diagnostics of one's QuickBooks Data files for Errors and accounting issues.

    ReplyDelete
  61. Any issue within these industry versions or those that we will discuss ahead, are dealt with utmost care by our QuickBooks Enterprise Support Number team.

    ReplyDelete
  62. QuickBooks Enterprise Technical support is a panacea for many forms of QuickBooks Enterprise tech issues. Moreover, nowadays businesses are investing a great deal of their money in accounting software such as for example QuickBooks Enterprise Support telephone number, as today everything is becoming digital. So, utilizing the advent of QuickBooks Enterprise Support Phone Number package, today, all accounting activities can be performed in just a press of a button. Although, accounting software applications are advantageous to deal with complicated and vast accounting activities.

    ReplyDelete
  63. QuickBooks Premier Support Phone Number are certified Pro-advisors’ and it has forte in furnishing any kind of technical issues for QuickBooks. They are expert and certified technicians of these domains like QuickBooks accounting, QuickBooks Payroll, Point of Sales, QuickBooks Merchant Services and Inventory issues to provide 24/7 service to the esteemed customers.

    ReplyDelete
  64. Professional accountant provide you absolute relaxation and time to focus on your core business. just through a call on the customer care or the toll-free QuickBooks Technical Support Number. With right service providers, you can be fully satisfied about the maintenance of your books of accounts. There are a lot of accounting firms that provide outsourcing bookkeeper services for low-cost rates.

    ReplyDelete
  65. Our QuickBooks Tech Support Number is obtainable for 24*7: Call @ QuickBooks Technical Support contact number any time Take delight in with an array of outshined customer service services for QuickBooks via quickbooks technical support contact number at any time and from anywhere.

    ReplyDelete
  66. What’s more important is to obtain the best help during the right time? Your time is valuable. You must invest it in a significant business decision and planning. You may also contact our QuickBooks customer care team using QuickBooks Support number. Anytime and anywhere you can solve your worries from our experts and Proadvisors via QuickBooks Support Phone Number.

    ReplyDelete
  67. The QuickBooks Desktop Support Number is toll-free in addition to professional technicians handling your support call can come up with an instantaneous solution that can permanently solve the glitches.

    ReplyDelete
  68. QuickBooks Technical Support Number supplies the Outmost Solution of the Software Issues. Although, QuickBooks is a robust accounting platform that throws less errors when compared with others. It is usually been probably the most challenging task to efficiently manage the business enterprise accounts in a geniune and proper way by simply getting the best and proper solutions.

    ReplyDelete

  69. Manage all your financial requirements on your fingertips with QuickBooks enterprise. Keep your accounts, payroll, inventory and much more in an organized way. The QuickBooks Tech Support Phone Number is toll-free therefore the professional technicians handling your support call may come up with an immediate solution that can permanently solve the glitches. Get built with some of the most brilliant accounting features such as for instance creating a company plan, easy remote access, inventory tracking and much more.

    ReplyDelete
  70. So in that case, you simply require the most sophisticated & highly certified experts, therefore we have given you our excellent professional or QuickBooks Tech Support Phone Number experts team and additionally they provide you with an immediate and incredibly easy solution of your all issues or errors.

    ReplyDelete
  71. Quickbooks Support Telephone Number
    QuickBooks has completely transformed the way people used to operate their business earlier. To get familiar with it, you should welcome this positive change.Supervisors at QuickBooks Help Number have trained all of their executives to combat the issues in this software. Utilizing the introduction of modern tools and approaches to QuickBooks, you can test new techniques to carry out various business activities. Basically, this has automated several tasks that have been being done manually for a long time. There are lots of versions of QuickBooks and each one has a unique features.

    ReplyDelete
  72. Here we list some definitions for the words contained in your error, in an attempt to help you understand your problem. This is a work in progress, so sometimes we might define the word incorrectly, so feel free to skip this section! If you would like to take a shot to Troubleshoot QuickBooks Error 9999 yourself, you can continue reading this blog. If you would like to take a shot to Troubleshoot QuickBooks Error 9999 yourself, you can continue reading this blog.

    ReplyDelete

  73. Excellent blog. Lots of useful information here, thanks for your effort!
    Real Estate Plots in Vizag

    ReplyDelete
  74. Quickbooks install diagnostic tool is a QuickBooks fix device that naturally recognizes and resolves the normal issues with QuickBooks. It helps in fixing the issues that happen in C++, .NET system, or the MSXML.

    ReplyDelete

  75. I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on your blog. You’ve made my day! Thx again!

    ReplyDelete
  76. Most People want to own more then one credit card but is it Good Idea to have more then One Credit Card , We have posted a blog on same , Go and check it out.

    ReplyDelete
  77. Looking for a reliable STQC approved testing company in India ? Look no further! Discover our accredited testing services that adhere to international standards, ensuring quality and compliance. Trust our expertise for accurate results, timely delivery, and comprehensive solutions. Contact us today for all your testing needs.

    ReplyDelete
  78. Honey trap cyber security is a social engineering attack where a cybercriminal uses a fake online persona to lure a victim into revealing confidential information or performing actions that compromise their security. This type of attack is often used to target high-profile individuals or organizations, but it can also be used against anyone who is not careful.

    ReplyDelete
  79. thanks for sharing this useful information with us and also this is a beautiful page also a more beautiful page and information is here for you , to open it click here performance testing Services in Noida .

    ReplyDelete
  80. Thanks for this information. I write articles about fantasy gaming apps. If you are interested in daman games appsdaman games app then do visit here.

    ReplyDelete
  81. This comment has been removed by the author.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...