How to update dropdownlist.selectedvalue into database?
-
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:
-
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:
There are lots of ways to update database from gridview. How you are doing it? What difficulty you are facing?
-
There are lots of ways to update database from gridview. How you are doing it? What difficulty you are facing?
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
-
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
Stop changing your question in each second. Search insert update delete using gridview[^] in google That will be better.