Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Update a Database Using Dropdownlist in ASP VB.Net

Update a Database Using Dropdownlist in ASP VB.Net

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasesysadminhelp
6 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    grafiksinc
    wrote on last edited by
    #1

    Hello all, First off I am using VB.net I have a dropdown list in the Item template. I would like the user to select a value and update the database without clicking an update button. Here is the Code for the DDL

    <asp:DropDownList ID="DropDownList1" runat="server"
    DataSourceID="SqlDataSource2" DataTextField="provider"
    DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged = "ddl_SelectedChange"
    SelectedValue='<%# Bind("provider") %>'>
    <asp:ListItem Value=""></asp:ListItem>
    </asp:DropDownList>

    here is my Behind code I am not sure what to put after the Dim statement

    Protected Sub ddl_SelectedChange(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim ddl = DirectCast(sender, DropDownList)

    Any help would be greatly appreciated

    D 1 Reply Last reply
    0
    • G grafiksinc

      Hello all, First off I am using VB.net I have a dropdown list in the Item template. I would like the user to select a value and update the database without clicking an update button. Here is the Code for the DDL

      <asp:DropDownList ID="DropDownList1" runat="server"
      DataSourceID="SqlDataSource2" DataTextField="provider"
      DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged = "ddl_SelectedChange"
      SelectedValue='<%# Bind("provider") %>'>
      <asp:ListItem Value=""></asp:ListItem>
      </asp:DropDownList>

      here is my Behind code I am not sure what to put after the Dim statement

      Protected Sub ddl_SelectedChange(ByVal sender As Object, ByVal e As System.EventArgs)
      Dim ddl = DirectCast(sender, DropDownList)

      Any help would be greatly appreciated

      D Offline
      D Offline
      Dinesh Mani
      wrote on last edited by
      #2

      Where is the rest of the code behind?? or do you want us to help you in writing that???

      G 1 Reply Last reply
      0
      • D Dinesh Mani

        Where is the rest of the code behind?? or do you want us to help you in writing that???

        G Offline
        G Offline
        grafiksinc
        wrote on last edited by
        #3

        Yes I am asking for hep is wrting that. Thanks,

        D 1 Reply Last reply
        0
        • G grafiksinc

          Yes I am asking for hep is wrting that. Thanks,

          D Offline
          D Offline
          Dinesh Mani
          wrote on last edited by
          #4

          * Now that you have the drop down list object, you can get the selected value/text. * You need to determine the row from which the event was fired and get the id. - Simple means would be to associate the primary key data to the dropdown using attributes. You can use these data to save the info to the database. HTH!

          G 1 Reply Last reply
          0
          • D Dinesh Mani

            * Now that you have the drop down list object, you can get the selected value/text. * You need to determine the row from which the event was fired and get the id. - Simple means would be to associate the primary key data to the dropdown using attributes. You can use these data to save the info to the database. HTH!

            G Offline
            G Offline
            grafiksinc
            wrote on last edited by
            #5

            <asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList> Here is the Behind Code

            Protected Sub dd_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            '*******************************************************
            '*This will get the dropdownlist which has been clicked*
            '*******************************************************
            Dim ddl As DropDownList
            ddl = DirectCast(sender, DropDownList)
            '***********************************************************************
            '*The row will be the currently selected row from which the dropdownlist*
            '*was clicked *
            '***********************************************************************
            Dim row As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow)
            '******************************
            '*Get the datakey for that row*
            '******************************
            Dim DataKey As String = GridView1.DataKeys(row.RowIndex).Values("IEN").ToString()
            '**********************
            '*Define Data Objects *
            '**********************
            Dim conn As SqlConnection
            Dim comm As SqlCommand

                '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                '\*Read the connectionstring from we.config\*
                '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("ER\_BloodHoundConnectionString").ConnectionString
                '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                '\*Initialize Connection\*
                '\*\*\*\*\*\*\*\*\*\*\*
            
            G 1 Reply Last reply
            0
            • G grafiksinc

              <asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList> Here is the Behind Code

              Protected Sub dd_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
              '*******************************************************
              '*This will get the dropdownlist which has been clicked*
              '*******************************************************
              Dim ddl As DropDownList
              ddl = DirectCast(sender, DropDownList)
              '***********************************************************************
              '*The row will be the currently selected row from which the dropdownlist*
              '*was clicked *
              '***********************************************************************
              Dim row As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow)
              '******************************
              '*Get the datakey for that row*
              '******************************
              Dim DataKey As String = GridView1.DataKeys(row.RowIndex).Values("IEN").ToString()
              '**********************
              '*Define Data Objects *
              '**********************
              Dim conn As SqlConnection
              Dim comm As SqlCommand

                  '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                  '\*Read the connectionstring from we.config\*
                  '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                  Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("ER\_BloodHoundConnectionString").ConnectionString
                  '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                  '\*Initialize Connection\*
                  '\*\*\*\*\*\*\*\*\*\*\*
              
              G Offline
              G Offline
              grafiksinc
              wrote on last edited by
              #6

              Thanks all. Problem solved. See previous post.:cool:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups