Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2007, 01:14 AM
Authorized User
 
Join Date: Jun 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default ListBox

hi,

I am using ListBox to collect data from users and save the data collected into a database. I have given a value to my LIstBox as
  0= house
  1= car
  2= boat

When the user selects House or car, or boat, i want 0,or 1, 0r 2 could be shown in a database instead og house or car or boat. how can i solve this problem?

Any help could be appreciated

Thank you in advance


 
Old October 19th, 2007, 02:06 AM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sandip.mis Send a message via Yahoo to sandip.mis
Default

Hi!
Good Afternoon.

Ur Problem is Solve.

:)

Steps

1:- Create Database
         And Create Table
               Table Field:
                    ID
                    Item
                    Value
       Then Complete Table

2:- Add New Page in Ur Application
        Drag Listbox
           <asp:ListBox ID="ListBox1" runat="server">
           <asp:ListItem Text="house" Value="0"></asp:ListItem>
           <asp:ListItem Text="car" Value="1"></asp:ListItem>
           <asp:ListItem Text="boat" Value="2"></asp:ListItem>
           </asp:ListBox>


         Drag Button
           <asp:Button ID="btnSave" runat="server" Text="Save" />

Step3:-
        Add Name Spaces
        Imports System.Data
        Imports System.Data.SqlClient

        Diclare Globaly Variable
         Dim Str As String
         Dim Sql As String
         Dim Con As New SqlConnection
         Dim Cmd As SqlCommand

         Button Click Event
Sql = "INSERT INTO TableName(Item,Value) Values(" & ListBox1.SelectedItem.Value & ",'" & ListBox1.SelectedItem.Text & "')"
        Con.Open()
        Cmd = New SqlCommand(Sql, Con)
        Cmd.ExecuteNonQuery()
        Con.Close()


        Page Load Event
          'This ConnectionString(ConStr)Define in Web.Config
        Str = System.Configuration.ConfigurationManager.AppSetti ngs("ConStr").ToString
        Con = New SqlConnection(Str)

Step4:- Connection String Define in Web.Config Like example.

      <appSettings>
        <add key="ConStr" value="Data Source=.\SQLEXPRESS;Initial Catalog=Your DatabaseName;Integrated Security=True"/>
    </appSettings>



ok
n any query u will contact me
[email protected]




Sandip
 
Old October 19th, 2007, 04:46 AM
Authorized User
 
Join Date: Jun 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi sandi!

thank you! problem solved!

belete






Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox obrienkev C# 2005 4 November 6th, 2007 03:15 AM
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
ListBox kanoorani Beginning VB 6 4 September 12th, 2006 12:28 PM
About listbox csc820203 C# 1 April 29th, 2004 06:17 AM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.