Get value from dropdownlistbox into gridview and update database in SQL Server 2005

  • Thread starter Thread starter BenCoo
  • Start date Start date
B

BenCoo

Hi,

I have a gridview control that displays data from 2 tabels in a sqlserver
2005 database. The table "Temperatures" has a field "LocationID" I populate
the gridview with a ObjectDataSource with the following connectionstring

Dim selTmpr As String = "SELECT Tmpr.TmprID, Tmpr.TmprName, Tmpr.TmprValue,
Tmpr.TmprRemark, Tmpr.TmprLocationID, Locations.Description " & _
"FROM Tmpr " & _
"LEFT OUTER JOIN Locations ON Tmpr.TmprLocationID = Locations.LocationID"

in the gridview I have ad a button "Edit" and when I press it the GV
changes into editmode displaying an update and cancel button. I have set the
property LocationID.visible to false and have added a collumn with a
DropDownListbox wich has a datasource "Locactions" (LocationID, Description)
in it. I have set the DataTextField to "Description" and the dataValueField
to "LocationID".

The ObjectDataSource has a Method "UpdateTemp"

How can I save the value of the DropDownList into my database ?

Many thanks in advance for any help on this,

Benny
 
type following in GridView1_itemUpdating Event.


e.NewValues("LocationID")=ctype(GridView1.FindControl("myDropDown"),DropDownList).SelectedValue

If you are inserting a New record, then type following in
GridView1_Iteminserting Event.

e.Values("LocationID")=ctype(GridView1.FindControl("myDropDown"),DropDownList).SelectedValue

Please change "myDropDown" with your DropDown Control ID.

Best Regards,

Luqman
 
Back
Top