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

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 (here). After that, you can post your question and our members will help you out.