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
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