Help Please: Adding a record picks up values from another row

E

Eagle

I have a grid that allows the user to have one of the cells automatically
default to a particular value (pulled from another control), or they can
enter it themselves. For instance, in a drop down box on the form, the user
can
choose a year. If year is blank, when they click on Add to add a row to the
datagrid, all fields are blank texboxes, and adding data works fine.

If, however, the year is selected, the first column is filled out for them
with the selected year. What is happening is when I retrieve the values of
that row in order to update the database, it retrieves all values correctly,
except for the year field. It gets the year field from the immediately
preceding
item in the datagrid. Why would it do that and what can I do about it.
This is my code:


Public Sub AddRecord(d as datagrid)
Dim ds As DataSet
Dim dt As DataTable
Dim dr As DataRow
ds = CType(HTTPContext.Current.Session("DS"), DataSet)

'copies only the structure of the dataset, no data
dt = ds.Tables(0).Clone
dr = dt.NewRow()
dt.Rows.Add(dr)

With d
.EditItemIndex = 0
.DataSource = dt
.DataBind()
If HTTPContext.Current.Session("Year") <> "" then
..Items(0).Cells(4).Text = HTTPContext.Current.Session("Year")
End With

End Sub


Public Sub GetValues(source, e, FieldCount)
Dim i as Integer
Try
arrValues.Clear
arrFields.Clear
Catch
end try
with e.Item
For i = 0 to FieldCount
With .Cells(i)
If .HasControls() then
if TypeOf .Controls(0) Is TextBox then
arrValues.Add(CType(.Controls(0), TextBox).Text)
arrFields.Add(Source.Columns(i).DataField)

End If
end with
Next
End With
End sub
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top