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

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
 
L

Luqman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top