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. How to update dropdownlist.selectedvalue into database?

How to update dropdownlist.selectedvalue into database?

Scheduled Pinned Locked Moved ASP.NET
tutorialdatabasehelpquestionannouncement
4 Posts 2 Posters 0 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.
  • E Offline
    E Offline
    edwin7nice
    wrote on last edited by
    #1

    hi all, It has dropdownlist in gridview. I face a difficult in update the dropdownlist.selectedvalue into database. May someone have simple example of source code to help me on this?:confused:

    S 1 Reply Last reply
    0
    • E edwin7nice

      hi all, It has dropdownlist in gridview. I face a difficult in update the dropdownlist.selectedvalue into database. May someone have simple example of source code to help me on this?:confused:

      S Offline
      S Offline
      Sherin Iranimose
      wrote on last edited by
      #2

      There are lots of ways to update database from gridview. How you are doing it? What difficulty you are facing?

      E 1 Reply Last reply
      0
      • S Sherin Iranimose

        There are lots of ways to update database from gridview. How you are doing it? What difficulty you are facing?

        E Offline
        E Offline
        edwin7nice
        wrote on last edited by
        #3

        in my gridview, i have linkbutton for add new row. below is the code for add new gridviewrow. but for the edit and update gridviewrow i still no has any idea. may u help me? Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=Display;Integrated Security=True;") Try If e.CommandName.Equals("New") Then Dim btnNew As LinkButton = TryCast(e.CommandSource, LinkButton) Dim row As GridViewRow = TryCast(btnNew.NamingContainer, GridViewRow) If row Is Nothing Then Return End If Dim txtPickTownCity As TextBox = TryCast(row.FindControl("PickTownCityTextBox"), TextBox) Dim dropdownlistPickState As DropDownList = TryCast(row.FindControl("DropDownList3"), DropDownList) Dim txtDeliveryTownCity As TextBox = TryCast(row.FindControl("DeliveryTownCityTextBox"), TextBox) Dim dropdownlistDeliveryState As DropDownList = TryCast(row.FindControl("DropDownList6"), DropDownList) Dim cmd As New SqlCommand("INSERT INTO [Address] ([Pick_Town_City], [Pick_State], [Delivery_Town_City], [Delivery_State]) VALUES (@Pick_Town_City, @Pick_State, @Delivery_Town_City, @Delivery_State)", conn) cmd.Parameters.AddWithValue("Pick_Town_City", txtPickTownCity.Text) cmd.Parameters.AddWithValue("Pick_State", dropdownlistPickState.SelectedValue) cmd.Parameters.AddWithValue("Delivery_Town_City", txtDeliveryTownCity.Text) cmd.Parameters.AddWithValue("Delivery_State", dropdownlistDeliveryState.SelectedValue) conn.Open() If cmd.ExecuteNonQuery() = 1 Then GridView1.DataBind() End If End If Catch ex As Exception Finally conn.Close() End Try End Sub

        S 1 Reply Last reply
        0
        • E edwin7nice

          in my gridview, i have linkbutton for add new row. below is the code for add new gridviewrow. but for the edit and update gridviewrow i still no has any idea. may u help me? Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=Display;Integrated Security=True;") Try If e.CommandName.Equals("New") Then Dim btnNew As LinkButton = TryCast(e.CommandSource, LinkButton) Dim row As GridViewRow = TryCast(btnNew.NamingContainer, GridViewRow) If row Is Nothing Then Return End If Dim txtPickTownCity As TextBox = TryCast(row.FindControl("PickTownCityTextBox"), TextBox) Dim dropdownlistPickState As DropDownList = TryCast(row.FindControl("DropDownList3"), DropDownList) Dim txtDeliveryTownCity As TextBox = TryCast(row.FindControl("DeliveryTownCityTextBox"), TextBox) Dim dropdownlistDeliveryState As DropDownList = TryCast(row.FindControl("DropDownList6"), DropDownList) Dim cmd As New SqlCommand("INSERT INTO [Address] ([Pick_Town_City], [Pick_State], [Delivery_Town_City], [Delivery_State]) VALUES (@Pick_Town_City, @Pick_State, @Delivery_Town_City, @Delivery_State)", conn) cmd.Parameters.AddWithValue("Pick_Town_City", txtPickTownCity.Text) cmd.Parameters.AddWithValue("Pick_State", dropdownlistPickState.SelectedValue) cmd.Parameters.AddWithValue("Delivery_Town_City", txtDeliveryTownCity.Text) cmd.Parameters.AddWithValue("Delivery_State", dropdownlistDeliveryState.SelectedValue) conn.Open() If cmd.ExecuteNonQuery() = 1 Then GridView1.DataBind() End If End If Catch ex As Exception Finally conn.Close() End Try End Sub

          S Offline
          S Offline
          Sherin Iranimose
          wrote on last edited by
          #4

          Stop changing your question in each second. Search insert update delete using gridview[^] in google That will be better.

          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