DataGrid edited values problem and autogenerated columns in DataGrid problem

Discussion in 'ASP .Net Web Controls' started by John Walsch, Jul 9, 2004.

  1. John Walsch

    John Walsch Guest

    Just to give a brief background what I'm trying to do, is I have a
    DataGrid with 2 static columns, and the rest are autogenerated (which
    have checkboxes). Everything works fine until I try to UPDATE edited
    values. Basically in my Page_Load section I have
    If Not IsPostBack Then
    BindData()
    End If

    where BindData binds the data to the DataGrid. So when I EDIT the
    DataGrid row, and the click on UPDATE, it calls my defined function.
    But when I get to that function, my autogenerated columns no longer
    exist, in which case I get the "System.ArgumentOutOfRangeException:
    Specified argument was out of the range of valid values. Parameter
    name: index" error when it tries to access the values of the
    checkboxes (in a for loop):
    For i As Integer = 2 To intColumnCount-1
    aDataTable.Rows(MyGrid.EditItemIndex)(i) =
    CType(e.Item.Cells(i).Controls(0), CheckBox).Checked
    Next

    Basically instead of my Column Count in the DataGrid to be 6, it only
    returns 3 (the 2 static columns that I defined and the
    EditCommandColumn).

    Ok, so to me it seemed like the DataGrid needed to be bound again, so
    in the Page_Load section I changed my code to just BindData() without
    the If Not IsPostBack statement. And what do you know, it worked, and
    I was able to edit my Values.... But then I tried to edit the data in
    the static columns, and the CType(e.Item.Cells(1).Controls(0),
    TextBox).Text would return the OLD value, not the new one. So I put
    the if Not IsPostBack statememnt back in the Page_Load section and now
    I get the new values from the two static columns, but as mentioned
    above I get that other error. :(

    Did anybody experience that problem before? If so do you know what the
    problem could be, and how can it be easily fixed?

    Thank You,
    John
    John Walsch, Jul 9, 2004
    #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. MS
    Replies:
    1
    Views:
    414
  2. MS
    Replies:
    1
    Views:
    353
  3. Luis Esteban Valencia
    Replies:
    0
    Views:
    672
    Luis Esteban Valencia
    Jan 11, 2005
  4. MikeG

    Sorting a datagrid with autogenerated columns

    MikeG, Jun 23, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    128
    MikeG
    Jun 23, 2004
  5. John Walsch

    Autogenerated Datagrid columns rebinding problem on postback

    John Walsch, Jul 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    165
    John Walsch
    Jul 12, 2004
Loading...

Share This Page