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

Discussion in 'ASP .Net Datagrid Control' started by Eagle, May 6, 2005.

  1. Eagle

    Eagle Guest

    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
     
    Eagle, May 6, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    646
    Big Brian
    Oct 14, 2003
  2. Andrew Jocelyn
    Replies:
    2
    Views:
    1,540
    Allen Chen [MSFT]
    Apr 27, 2009
  3. D
    Replies:
    0
    Views:
    230
  4. Replies:
    0
    Views:
    112
  5. Maximus
    Replies:
    2
    Views:
    195
    Bob Barrows [MVP]
    Apr 12, 2007
Loading...

Share This Page